home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / Virtual User tools / SPEC S&L v.1.0.1 / Libraries / UserInterface.Lib < prev    next >
Encoding:
Text File  |  1993-12-17  |  92.2 KB  |  2,585 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:    UserInterface.Lib
  5. #
  6. #    Contains:    Library of tasks that manipulate some aspect of the Human Interface.
  7. #
  8. #    Written by:    Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
  9. #
  10. #    Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #    <2.0.22>     12/16/93    KTA        SizeWindow() - fixed bug where trying to size window smaller 
  19. #                                    than 20 pixels
  20. #    <2.0.21>     12/2/93    KTA        DialogCheck() - supports button descriptors, TypeStr() added
  21. #                                    gTypeStrOverRide.
  22. #    <2.0.20>    11/19/93    NAGA    modify TCS format
  23. #    <2.0.19>    11/19/93    KTA        A couple of changes for INTL and Performance
  24. #    <2.0.18>    11/11/93    KTA        DialogCheck() - If no pFindStaticText is passed in, it will work
  25. #                                    on any dialog.
  26. #    <2.0.17>     9/22/93    KTA        Removed a projector error message.
  27. #    <2.0.16>     9/22/93    KTA        Changed gEndTimer task references to reflect the task in which
  28. #                                    the references are located.
  29. #    <2.0.15>     9/13/93    KTA        SelectButton(), SelectRadioButton(), selectCheckBox - added
  30. #                                    support for selecting by ordinality.
  31. #    <2.0.14>     9/13/93    KTA        Updated TestLevel specification and DismissDialog() now supports
  32. #                                    KeyEq('.').
  33. #    <2.0.13>      9/9/93    KTA        SelectMenuItem(), KeyEq() - Changed output line so it does not
  34. #                                    say 'About to …'
  35. #    <2.0.12>      9/7/93    KTA        KeyEq() - Added pOtherKey := 3 (controlkey).
  36. #    <2.0.11>      9/1/93    KTA        Parameter Updates
  37. #    <2.0.10>      9/1/93    KTA        More header updates - Window section
  38. #     <2.0.9>      9/1/93    KTA        Updated task headers and parameters.
  39. #     <2.0.8>     8/25/93    KTA        Added support for parity checking the TCS stack.
  40. #     <2.0.7>     7/30/93    KTA        Updates to DismissDialog(), DialogHandler(), and DialogCheck(),
  41. #                                    also updated a couple of descriptors that were still contained
  42. #                                    within lists.
  43. #     <2.0.6>     7/23/93    KTA        CloseWindow() - needed a wait(2) and call IsStandardFile().
  44. #     <2.0.5>     7/22/93    KTA        FindWindow() - if specifier is a descriptor needed a Dammit
  45. #                                    operator (!)
  46. #     <2.0.4>     7/20/93    KTA        A couple of more changes to support FindWindow().
  47. #     <2.0.3>     7/19/93    KTA        Updated for FindWindow to handle descriptors.
  48. #     <2.0.2>      7/7/93    KTA        Changed DismissDialog() so it would properly verify whether
  49. #                                    dialog was dismissed.
  50. #     <2.0.1>      7/6/93    KTA        Performance support and other misc. changes.
  51. #        <1+>     5/21/93    NAGA        Adding header and porting old files to follow new standards
  52. #
  53. # ****************************************************************************
  54. #
  55.  
  56.  
  57. ########################################################################
  58. #                            External libraries 
  59. #=======================================================================
  60. Libraries "Geometry.lib","String.Lib","Output.lib","TCS.lib", "StandardFile.lib";
  61.  
  62.  
  63. #=======================================================================
  64. # Menu related tasks:
  65. #=======================================================================
  66.  
  67. ########################################################################
  68. #                 SelectMenuItem(pMenu1, pMenu2, pMenu3)                    
  69. #=======================================================================
  70. # Author:           Kevin Avoy
  71. # Description:        Selects the menu item by its title or ordinality.
  72. #                    All parameters are expected to be the same type.
  73. # Parameters:        pMenu1 := Menu item to be selected.
  74. #                    pMenu2 := Menu name if non-hier menu and
  75. #                                 Level 2 menu item if hier menu.
  76. #                    pMenu3 := "" if non-hier menu.
  77. #                                 Menu name if hier menu.
  78. # Returns:            menuTitle - MenuItem name that selection was successful
  79. #                    0 - Couldn't select menu item
  80. # Notes:            It is not mandatory to specify input parameters 'pMenu2' 
  81. #                    or 'pMenu3'.  In that case, default value, "",
  82. #                    will be used.
  83. #=======================================================================
  84. # History:
  85. # KTA    7/6/93        Performance support: Call (gBeginTimer);
  86. # KTA    7/6/93        Readded regularExpression support
  87. # KTA    9/9/93        Changed output line so it does not say 'About to …'
  88. # KTA    9/21/93        Changed gBeginTimer to gPreSelectMenuItemHook, gPostSelectMenuItemHook
  89. ########################################################################
  90. TASK SelectMenuItem(pMenu1, pMenu2 := "", pMenu3 := "") 
  91. begin
  92.     returnVal := 0;
  93.     #println "SelectMenuitem∂( ",pMenu1,',',pMenu2,',',pMenu3,"∂)";
  94.     if not (match [window o:1 s:Dialog c:0 g:0 z:0]!)
  95.     begin
  96.         if ((Typeof(pMenu1) = 'string') or (Typeof(pMenu1) = 'regularExpression'))
  97.         begin
  98.             if (pMenu3 = "")                    # Match non-hier menus            
  99.                 ourMenuItem := match [menuItem t: pMenu1 m:[menu t: pMenu2]];
  100.             else                        # Match hier menus                
  101.                 ourMenuItem :=match [menuItem t:pMenu1 
  102.                                               m:[menuitem t:pMenu2 
  103.                                               m:[menu t:pMenu3]]];
  104.         end;
  105.         else
  106.         begin
  107.             if not(pMenu3)                    # Match non-hier menus            
  108.                 ourMenuItem := match [menuItem o:pMenu1 m:[menu o:pMenu2]];
  109.             else                        # Match hier menus                
  110.                 ourMenuItem :=match [menuItem o:pMenu1 
  111.                                               m:[menuitem o:pMenu2 
  112.                                               m:[menu o:pMenu3]]];
  113.         end;
  114.     
  115.         if (ourMenuItem)             # Not there
  116.         begin
  117.             if (ourMenuItem.e)         #  enabled
  118.             begin
  119.                 menuTitle := ourMenuItem.t;
  120.                 LogStr("Selecting the '{menuTitle}' menu item");
  121.                 if (global gMacstiming) and (global gPreSelectMenuItemHook)
  122.                 # possible changes to collect macstime data accurately
  123.                 # after the menu item is selcted Finder doesn't get time so the AppleEvent
  124.                 # can be parsed and executed by the MacsTime CDEV - So we need to start
  125.                 # MacsTime before the menu select
  126.                     Call (gPreSelectMenuItemHook);
  127.                 
  128.                 select ourMenuItem!;
  129.                     
  130.                 if not(gMacsTiming) and (global gPostSelectMenuItemHook)
  131.                     Call (gPostSelectMenuItemHook);
  132.             
  133.                 returnVal := menuTitle;
  134.             end;
  135.             else 
  136.             begin
  137.                 menuTitle := ourMenuItem.t;
  138.                 LogStr("!@#$% Menu item {menuTitle} is not enabled to select.");
  139.             end;
  140.         end;
  141.         else 
  142.             LogStr("!@#$% Could not find menu item {pMenu1} to select");
  143.     end;
  144.     else
  145.     begin
  146.         LogStr("!@#$% Dialog present can't select menuItems");
  147.         DialogCheck(, 1);        # Attempt to dismiss the dialog
  148.     end;
  149.         
  150.     return(returnVal);
  151. end; # SelectMenuItem()
  152.  
  153. #########################################################################
  154. #                             FindMenu(pTheMenuItem)
  155. #=======================================================================
  156. # Author:              KTA
  157. # Description:        Returns the Menu(s) in which <pTheMenuItem> is contained.
  158. # Parameters:        pTheMenuItem    :=    Title of the menuitem to be searched for.
  159. # Returns:            0    -    Can't match <pTheMenuItem>.
  160. #                    {theMenu,""}    -    for a nonHierarchical menu.
  161. #                    {theHMenuItem, theMenu}    -    if its hierarchical.
  162. # Example:            MyMenu := FindMenu('Paste');
  163. #=======================================================================
  164. # History:
  165. #
  166. #########################################################################
  167. TASK FindMenu(pTheMenuItem)
  168. begin
  169.     MenuName := match[menuitem t:pTheMenuItem];
  170.     if (MenuName)
  171.     begin
  172.         IsMenu := descType(MenuName.m);
  173.         if (IsMenu = 'menu')
  174.         begin
  175.             theMenu := MenuName.m.t;
  176.             Return({theMenu,""});
  177.         end;
  178.         else If (IsMenu = 'menuItem')
  179.         begin
  180.             theHMenuItem := MenuName.m.t;
  181.             MenuName := match [menuItem t:pTheMenuItem 
  182.                                               m:[menuitem t:theHMenuItem 
  183.                                                              m:[menu t:?theMenu]]];
  184.             Return({theHMenuItem, theMenu});
  185.         end;
  186.     end;
  187.     else Return(0);
  188. end; # FindMenu()
  189.  
  190. #########################################################################
  191. #                            KeyEq(pKeyEquiv,pOtherkey, pNumTimes)
  192. #========================================================================
  193. # Author:        KTA
  194. # Description:    This routine will select the Keyboard Equiv <pKeyEquiv>
  195. # Parameters:    pKeyEquiv -    string holding character to be typed with
  196. #                            command key down.
  197. #                pOtherkey -    integer -  representing special keys to hold 
  198. #                            down in conjunction with the command key
  199. #                    1 - Shift key
  200. #                    2 - Option key
  201. #                    3 - Control key
  202. #                pNumTimes -    integer - representing number of times to type keyEq.
  203. # Returns:        None
  204. # Examples:        KeyEq("q");
  205. #========================================================================
  206. # History:
  207. # KTA    7/2/93        Added pNumTimes parameter for number of times to type KeyEq.
  208. # KTA    7/6/93        Performance support: Call (gBeginTimer);
  209. # KTA    9/7/93        Added pOtherKey := 3 (controlkey)
  210. # KTA    9/9/93        Changed output line so it does not say 'About to …'
  211. # KTA    9/21/93        Changed gBeginTimer to gPreKeyEqHook
  212. #########################################################################
  213. TASK KeyEq(pKeyEquiv, pOtherkey := 0, pNumTimes := 1) 
  214. begin
  215.     KeyList := { '',''};
  216.     if (pOtherkey =1) 
  217.         KeyList := {ShiftKey,'-Shift'};
  218.     else if (pOtherkey = 2) 
  219.         KeyList := {Optionkey,'-Option'};
  220.     else if (pOtherkey = 3) 
  221.         KeyList := {Controlkey,'-Control'};
  222.  
  223.     WhichKey := KeyList[2];
  224.     LogStr("Pressing the ∂('{pKeyEquiv}'∂) key and the Command{WhichKey} key {pNumTimes} times");
  225.     
  226.     pressKey k:{ commandKey,KeyList[1]};
  227.     For i := 1 to pNumTimes
  228.     begin
  229.         if (global gPreKeyEqHook)
  230.             Call (gPreKeyEqHook);
  231.         type k : { pKeyEquiv };
  232.     end;
  233.  
  234.     releaseKey k:{ commandKey,KeyList[1] };
  235. end; # KeyEq()
  236.  
  237.  
  238. #=======================================================================
  239. # Window related tasks:
  240. #=======================================================================
  241. # Description:    This section contains VU code for running tests on the
  242. #                basic controls of a window.
  243. #
  244. #            *** The main task in this section is TestWindow().  It is used to
  245. #                perform a number of window test automatically.
  246. #
  247. #                The window related tasks in this library are grouped in the
  248. #                following logical order:
  249. #
  250. #                TestWindow(pSpecifier, pFunctionList, pRestoreWindow, pNumTimes, pDragXY) 
  251. #                WindowFunction(pSpecifier, pTheFunction, pDragXY, pDestinationPoint) 
  252. #                DragAcrossScreens(pSpecifier,pDragXY) 
  253. #                SizeAcrossScreens(pSpecifier, pDragXY) 
  254. #                AdjustRectToScreen(pTheRect) 
  255. #                CoverCompletely (pFirstWindow, pSecondWindow)
  256. #                ResetWindow(pTheWindow) 
  257. #                SelectWindow(pSpecifier) 
  258. #                UnCoverWindow(pSpecifier, pFrontWindow)
  259. #                DragWindow(pHorizontalPixels, pVerticalPixels, pSpecifier,pAbsolutely) 
  260. #                SizeWindow(pPixelsWide, pPixelsHigh, pSpecifier, pAbsolutely) 
  261. #                ZoomWindow(pSpecifier) 
  262. #                CloseWindow(pHowClose,pOverWrite,pSpecifier,pNewDocName) 
  263. #                ScrollWindow(pWhichScrollBar,pDesirePosition,pMaxPosition) 
  264. #                GetVHScrollBars()
  265. #                CloseAllWindows()
  266. #                FindWindow(pSpecifier) 
  267. #                GetRandomPointsRelativeToWindow(pInset, pSpecifier, pNumPts)
  268. #
  269. #
  270. #
  271. #
  272. #
  273. #
  274. #
  275. #     Copyright Apple Computer, Inc. 1985-1990
  276. #    All rights reserved
  277. #
  278. #========================================================================
  279. # History:
  280. #
  281. #########################################################################
  282.  
  283.  
  284. #########################################################################
  285. #     TestWindow(pSpecifier,pFunctionList,pRestoreWindow,pNumTimes,pDragXY)
  286. #=======================================================================
  287. # Author:         Nick Vaccaro
  288. #
  289. # Description:    Performs the specified functions as defined in the input
  290. #                parameter pFunctionList.  If pFunctionList is not passed,
  291. #                or is passed as 0, then the following operations are
  292. #                performed on the window specified by input parameter
  293. #                pSpecifier.  The default behavior will perform the
  294. #                following behaviors on the frontmost window* (see *NOTE).
  295. #                Listed below is the list of function numbers and a brief
  296. #                description of what that particular function does:
  297. #
  298. #                    #0    Complete Window Test
  299. #                            Performs functions 1 through 17
  300. #                            (17 is done twice - zoom & zoom back)
  301. #                    #1    Resize to random width and height.
  302. #                    #2    Attempt resize to 20,20 (should not allow it)
  303. #                    #3    Scroll the vertical scroll bar to random location.
  304. #                    #4    Scroll the vertical scroll bar to end location.
  305. #                    #5    Scroll the vertical scroll bar to beginning location.
  306. #                    #6    Scroll the vertical scroll bar to original location.
  307. #                    #7    Scroll the horizontal scroll bar to random location.
  308. #                    #8    Scroll the horizontal scroll bar to end location.
  309. #                    #9    Scroll the horizontal scroll bar to beginning location.
  310. #                    #10    Scroll the horizontal scroll bar to original location.
  311. #                    #11    Resize window to largest possible and then
  312. #                    #12    Resize back to smallest window size
  313. #                    #13 Size window across screen border to second screen
  314. #                        (if 2 screens) and back
  315. #                    #14    Drag window across screen border and back
  316. #                    #15    Drag random location and back to original location
  317. #                    #16    Drag window back to original location.
  318. #                    #17    Zoom.
  319. #                    #18 Complete Window Size Test
  320. #                            Performs functions 1,2,11,12, and 13
  321. #                    #19 Complete Window Scroll Test
  322. #                            Performs functions 3,4,5,6,7,8,9, and 10
  323. #                    #20 Complete Window Drag Test
  324. #                            Performs functions 14,15, and 16
  325. #                    #21 Complete Window Zoom Test
  326. #                            Performs function 17 twice (zoom - zoom back)
  327. #                    #22 A More Complete Window Scroll Test
  328. #                            Performs functions 2,3,4,5,6,7,8,9, and 10.
  329. #                            This is the same as #19 except it sizes the
  330. #                            window to the smallest possible size.  This
  331. #                            is better in that it is more likely for the
  332. #                            scrollbars to be active.
  333. #                    #23 A More Complete Window Drag Test
  334. #                            Performs functions 2,14,15, and 16
  335. #                            This is the same as #20 except it sizes the
  336. #                            window to the smallest possible size.  This
  337. #                            is better in that it is more likely for the
  338. #                            window to be able to be dragged across screen
  339. #                            boundaries.
  340. #        
  341. # Parameters: pSpecifier -  Title or Ordinality or partial window descriptor
  342. #                            of window to be tested
  343. #                            If this parameter is not passed, default
  344. #                            behavior of Tasks will be used (generally the
  345. #                            frontmost window - see *NOTE below)
  346. #
  347. #            pFunctionList - A list containing the functions to be
  348. #                            executed and the number of times to exercize
  349. #                            each function.  The functions will be executed
  350. #                            in the order that they are defined.  The default
  351. #                            is to execute all tests once. The pFunctionList
  352. #                            parameter can have the following formats:
  353. #                            
  354. #                            integer:
  355. #                                    Number of a single test to run once.
  356. #                                    Functions are numbered above.
  357. #                                    0 to execute full sequence once.
  358. #
  359. #                            list of integers:
  360. #                                    A list of test numbers to run -
  361. #                                    each test will be run once and
  362. #                                    in the same order that they appear
  363. #                                    in the list.
  364. #
  365. #                            list of lists:
  366. #                                    A list of {test#,#times} lists
  367. #                                    where test# is the number of the
  368. #                                    test and #times is the number of
  369. #                                    times to execute that test.  Each
  370. #                                    list will be processed in order.
  371. #                                    If an item in the main list is an
  372. #                                    integer and not a list, that test
  373. #                                    number will be executed once.
  374. #
  375. #                pRestoreWindow -    1 to restore window to original size,
  376. #                                    location, and scrollbar status.
  377. #                                0 not to restore window
  378. #
  379. #                pNumTimes -    integer for number of times to execute test
  380. #
  381. #                pDragXY -    Upper Left-Top corner to drag window to
  382. #
  383. # Returns:        0 - Couldn't find specified window
  384. #                1 - Executed OK
  385. #
  386. # Assumptions:    None
  387. #
  388. #========================================================================
  389. # History:
  390. #
  391. #########################################################################
  392. TASK TestWindow(pSpecifier := 0, pFunctionList := 0, pRestoreWindow := 0, pNumTimes := 1, pDragXY := {0,20}) 
  393. begin
  394.     if (global gScreenInset)
  395.         pDragXY := {gScreenInset[1], gScreenInset[2]};
  396.     global OrigScrollBars := 0;    # default to scrollbars at beginning
  397.     returnVal := 0;
  398.  
  399.     # get the window's original status - if we can't find it, return 0
  400.     originalWindowDesc := FindWindow(pSpecifier);
  401.     if (originalWindowDesc)
  402.     begin
  403.         
  404.         # set all original window variable information
  405.         originalOrd := originalWindowDesc.o;
  406.         if (originalOrd <> 1)
  407.             originalWindowDesc := SelectWindow(pSpecifier);
  408.         originalOrd := originalWindowDesc.o;
  409.         theTitle := originalWindowDesc.t;
  410.         oldRect := originalWindowDesc.r;
  411.         theDesc := [window t:theTitle o:originalOrd];    # Partial window descriptor
  412.         
  413.         # and scroll bar positions
  414.         OrigScrollBars := collect [scrollbar w:[window t:theTitle o:originalOrd]]!;
  415.         if (card OrigScrollBars >= 2) begin
  416.             hscroll := OrigScrollBars[2];
  417.             vscroll := OrigScrollBars[1];
  418.         end;
  419.         else if (card OrigScrollBars = 1)
  420.             vscroll := OrigScrollBars[1];
  421.         
  422.         if (hscroll)
  423.             OrigScrollBars := {vscroll.s,hscroll.s};
  424.         else if (vscroll)
  425.             OrigScrollBars := {vscroll.s};
  426.         
  427.         # if pFunctionList = 0, run default behavior
  428.         if (pFunctionList = 0) begin
  429.             println;
  430.             println "===========================================================================";
  431.             LogStr("Starting Complete Window Test...");
  432.             #pFunctionList := {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,17};
  433.             pFunctionList := {17,17,12,11,1,3,4,5,6,7,8,9,10,13,14,15,11};
  434.         end;
  435.  
  436.         # first, drag the window onto screen to assure more success at functions
  437.         # Drag it to the desired location (if needed)
  438.         if not ((tempRect[1] = pDragXY[1]) and (tempRect[2] = pDragXY[2]))
  439.             if global gDoWindowList[3] # if dragging is available
  440.                 DragWindow(pDragXY[1],pDragXY[2],theDesc,1);    # Call with partial window descriptor
  441.         
  442.     
  443.         for iterationNum := 1 to pNumTimes do begin
  444.             # Now perform our test(s)
  445.             if (TypeOf(pFunctionList) = "integer") begin    # it's a single test
  446.                 WindowFunction(theDesc, pFunctionList, pDragXY, oldRect);
  447.             end;
  448.             else begin    # it's a list of tests
  449.                 for currentFunction := 1 to card pFunctionList do begin
  450.                     theFunction := pFunctionList[currentFunction];
  451.                     if (TypeOf(theFunction) = "list") begin
  452.                         for tempCount := 1 to theFunction[2] begin
  453.                             if (WindowFunction(theDesc,theFunction[1],pDragXY,oldRect))
  454.                                 returnVal := 1;    
  455.                         end;
  456.                     end;
  457.                     else begin
  458.                         if (WindowFunction(theDesc,theFunction,pDragXY,oldRect))
  459.                             returnVal := 1;    
  460.                     end;
  461.                 end;
  462.             end;
  463.         end;
  464.         
  465.         if (pRestoreWindow)
  466.             ResetWindow(originalWindowDesc);
  467.         
  468.         returnVal := 1;
  469.     end;
  470.     else
  471.         LogStr("Couldn't find specified window for TestWindow");
  472.     
  473.     return(returnVal);
  474. end; # TestWindow()
  475.  
  476.  
  477. #########################################################################
  478. #         WindowFunction(pSpecifier, pTheFunction, pDragXY,pDestinationPoint)
  479. #=======================================================================
  480. # Author:         NJV
  481. # Description:    Performs the specified function defined in the input
  482. #                parameter pTheFunction to the window specified by pSpecifier.
  483. #                Listed below is the list of function numbers and a brief
  484. #                description of what that particular function does:
  485. #
  486. #                    #1    Resize to random width and height.
  487. #                    #2    Attempt resize to 20,20 (should not allow it)
  488. #                    #3    Scroll the vertical scroll bar to random location.
  489. #                    #4    Scroll the vertical scroll bar to end location.
  490. #                    #5    Scroll the vertical scroll bar to beginning location.
  491. #                    #6    Scroll the vertical scroll bar to original location.
  492. #                    #7    Scroll the horizontal scroll bar to random location.
  493. #                    #8    Scroll the horizontal scroll bar to end location.
  494. #                    #9    Scroll the horizontal scroll bar to beginning location.
  495. #                    #10    Scroll the horizontal scroll bar to original location.
  496. #                    #11    Resize window to largest possible
  497. #                    #12    Resize back to smallest window size
  498. #                    #13 Size window across screen border to second screen
  499. #                        (if 2 screens) and back
  500. #                    #14    Drag window across screen border and back
  501. #                    #15    Drag window to random location.
  502. #                    #16    Drag window to location specified by pDestinationPoint.
  503. #                    #17    Zoom.
  504. #                    #18 Complete Window Size Test
  505. #                            Performs functions 1,2,11,12, and 13
  506. #                    #19 Complete Window Scroll Test
  507. #                            Performs functions 3,4,5,6,7,8,9, and 10
  508. #                    #20 Complete Window Drag Test
  509. #                            Performs functions 14,15, and 16
  510. #                    #21 Complete Window Zoom Test
  511. #                            Performs function 17 twice (zoom - zoom back)
  512. #                    #22 A More Complete Window Scroll Test
  513. #                            Performs functions 2,3,4,5,6,7,8,9, and 10
  514. #                            This is the same as #19 except it sizes the
  515. #                            window to the smallest possible size.  This
  516. #                            is better in that it is more likely for the
  517. #                            scrollbars to be active.
  518. #                    #23 A More Complete Window Drag Test
  519. #                            Performs functions 2,14,15, and 16
  520. #                            This is the same as #20 except it sizes the
  521. #                            window to the smallest possible size.  This
  522. #                            is better in that it is more likely for the
  523. #                            window to be able to be dragged across screen
  524. #                            boundaries.
  525. #
  526. # Parameters:    pSpecifier -    Title of window to be tested
  527. #
  528. #                pTheFunction -    The number of the test to run
  529. #
  530. #                pDragXY -    Left-Top point (list of {left,top}) to drag
  531. #                            window to. (used if pTheFunction = 13 or 14)
  532. #    
  533. #                pDestinationPoint -    Left/Top point (list of {left,top}) of
  534. #                                    original window (used if pTheFunction = 16)
  535. #
  536. # Returns:        0 - Couldn't perform specified Task
  537. #                1 - Executed OK
  538. #
  539. # Assumptions:    None.
  540. #
  541. # *NOTE:        The TestWindow() function provides much more versatility
  542. #                than this routine.  WindowFunction is called by TestWindow.
  543. #========================================================================
  544. # History:
  545. #
  546. #########################################################################
  547. TASK WindowFunction(pSpecifier, pTheFunction, pDragXY, pDestinationPoint) 
  548. begin
  549.     if (global gScreenInset)
  550.         inset := gScreenInset;
  551.     else
  552.         inset := { 0,20,0,0};
  553.     # if the user wants a multiple function (#18-#23), set FunctionList
  554.     # accordingly
  555.     if ((pTheFunction >= 18) and (pTheFunction <= 23)) begin
  556.         
  557.         # reset FunctionList
  558.         if (pTheFunction = 18) begin
  559.             println;
  560.             println "===========================================================================";
  561.             LogStr("Starting Complete Window Size Test...");
  562.             FunctionList := {1,2,11,12,13};
  563.         end;
  564.         else if (pTheFunction = 19) begin
  565.             println;
  566.             println "===========================================================================";
  567.             LogStr("Starting Complete Window Scroll Test...");
  568.             FunctionList := {3,4,5,6,7,8,9,10};
  569.         end;
  570.         else if (pTheFunction = 20) begin
  571.             println;
  572.             println "===========================================================================";
  573.             LogStr("Starting Complete Window Drag Test...");
  574.             FunctionList := {14,15,16};
  575.         end;
  576.         else if (pTheFunction = 21) begin
  577.             println;
  578.             println "===========================================================================";
  579.             LogStr("Starting Complete Window Zoom Test...");
  580.             FunctionList := {17,17};
  581.         end;
  582.         else if (pTheFunction = 22) begin
  583.             println;
  584.             println "===========================================================================";
  585.             LogStr("Starting Complete Window Scroll Test - Will Shrink Window First...");
  586.             FunctionList := {2,3,4,5,6,7,8,9,10};
  587.         end;
  588.         else if (pTheFunction = 23) begin
  589.             println;
  590.             println "===========================================================================";
  591.             LogStr("Starting Complete Window Drag Test - Will Shrink Window First...");
  592.             FunctionList := {2,14,15,16};
  593.         end;
  594.             
  595.         # now execute each test using recursion
  596.         noError := 1;    # no errors yet
  597.         for each item in FunctionList begin
  598.             if not (WindowFunction(pSpecifier,item,pDragXY,pDestinationPoint))
  599.                 foundError := 1;
  600.         end;
  601.         return(foundError);
  602.     end;
  603.  
  604.     if (pTheFunction = 1)    #1    Resize to random width and height.
  605.         return(SizeWindow('random','random',pSpecifier));                            #1
  606.     
  607.     else if (pTheFunction = 2)    #2    Attempt resize to 20,20 (should not allow it)
  608.         return(SizeWindow(20,20,pSpecifier));                                        #2
  609.     
  610.     else if ((pTheFunction >= 3) and (pTheFunction <= 10)) begin
  611.         # get the old value of the scroll bars to replace scrollbars as they were found.
  612.         theScrollBars := GetVHScrollBars();
  613.         vertical := theScrollBars[1];
  614.         horizontal := theScrollBars[2];
  615.         oldVertical := vertical.s;
  616.         oldHorizontal := horizontal.s;
  617.         
  618.         if (pTheFunction = 3)    #3    Scroll the vertical scroll bar to random location.
  619.             return(ScrollWindow('V'));                                            #3
  620.  
  621.         else if (pTheFunction = 4)    #4    Scroll the vertical scroll bar to end location.
  622.             return(ScrollWindow('V',1,1));                                        #4
  623.         
  624.         else if (pTheFunction = 5)    #5    Scroll the vertical scroll bar to beginning location.
  625.             return(ScrollWindow('V',0,1));                                        #5
  626.         
  627.         else if (pTheFunction = 6)    #6    Scroll the vertical scroll bar to original location.
  628.             return(ScrollWindow('V',oldVertical[1],oldVertical[2]));            #6
  629.             
  630.         else if (pTheFunction = 7)    #7    Scroll the horizontal scroll bar to random location.
  631.             return(ScrollWindow('H'));                                            #7
  632.         
  633.         else if (pTheFunction = 8)    #8    Scroll the horizontal scroll bar to end location.
  634.             return(ScrollWindow('H',1,1));                                        #8
  635.         
  636.         else if (pTheFunction = 9)    #9    Scroll the horizontal scroll bar to beginning location.
  637.             return(ScrollWindow('H',0,1));                                        #9
  638.         
  639.         else    #10    Scroll the horizontal scroll bar to original location.
  640.             return(ScrollWindow('H',oldHorizontal[1],oldHorizontal[2]));        #10
  641.     end;
  642.     
  643.     else if (pTheFunction = 11) begin    #11    Resize window to largest possible
  644.         # Match to get new rect
  645.         theWind := FindWindow(pSpecifier);
  646.         if not (theWind)
  647.             return(0);
  648.         else
  649.             newRect := theWind.r;
  650.         # get screen coordinates
  651.         match [screen r:?theScreenRect m:true]!;
  652.         
  653.         #11    Resize window to largest possible
  654.         return(SizeWindow(theScreenRect[3]-newRect[1]-inset[3],theScreenRect[4]-newRect[2]-inset[4],pSpecifier));    #11
  655.     end;
  656.     
  657.     else if (pTheFunction = 12)    #12    Resize to smallest window size
  658.         return(SizeWindow(20,20,pSpecifier));                                        #12
  659.     
  660.     else if (pTheFunction = 13)    #13 Size window across screen border to second screen (if 2 screens) and back
  661.         return(SizeAcrossScreens(pSpecifier,pDragXY));                                #13
  662.     
  663.     else if (pTheFunction = 14)    #14    Drag window across screen border and back
  664.         return(DragAcrossScreens(pSpecifier,pDragXY));                                #14
  665.     
  666.     else if (pTheFunction = 15)    #15    Drag random location.
  667.         return(DragWindow('RandomReturn','Random',pSpecifier));                            #15
  668.     
  669.     else if (pTheFunction = 16)     #16    Drag window back to original location.
  670.         return(DragWindow(pDestinationPoint[1],pDestinationPoint[2],pSpecifier));    #16
  671.     
  672.     else if (pTheFunction = 17)     #17    Zoom.
  673.         return(ZoomWindow(pSpecifier));                                            #17
  674.  
  675.     else
  676.         LogStr("!@#$% - scriptor error - Unknown Function Number ∂"{pTheFunction}∂" passed to WindowFunction()");
  677.     return(0);
  678. end;
  679.  
  680.  
  681. #########################################################################
  682. #                    DragAcrossScreens(pSpecifier,pDragXY)
  683. #========================================================================
  684. # Author:            NJV
  685. # Description:        If there are two screens present, this task will drag
  686. #                    the window specified by <pSpecifier> so that half of the
  687. #                    window is on the first screen and half of the window
  688. #                    is on the second screen.  
  689. # Parameters:        pSpecifier - title of window to drag
  690. #                    pDragXY - a list of two co-ordinates (left-top) pixel
  691. #                            to drag window to (i.e.{0,20} to avoid menu bar
  692. #                            on main screen).
  693. # Returns:            1 - successful
  694. #                    0 - unsuccessful
  695. # Examples:            DragAcrossScreens("Untitled",{0,20}).
  696. # Assumptions:        None
  697. #========================================================================
  698. # History:
  699. # KTA    8/24/93        TCS stack parity check
  700. #########################################################################
  701. TASK DragAcrossScreens(pSpecifier,pDragXY) 
  702. begin
  703.     returnVal := 0;
  704.     failStr := '';
  705.     # get screen information
  706.     s1 := match [screen m:true]!;
  707.     s2 := match [screen m:false]!;
  708.     wind := FindWindow(pSpecifier);
  709.     
  710.     TCSStart({ 2, global kTCSetUIWindowDrag },"DragAcrossScreens");
  711.     if (s2 and s1 and wind)
  712.     begin
  713.         # get half of the window height and half of the window width
  714.         hWidth := ((wind.r[3] - wind.r[1])/2);
  715.         hHeight := ((wind.r[4] - wind.r[2])/2);
  716.         
  717.         # assign various sides of screens to easier and shorter variables
  718.         l1 := s1.r[1];    r1 := s1.r[3];    t1 := s1.r[2];    b1 := s1.r[4];
  719.         l2 := s2.r[1];    r2 := s2.r[3];    t2 := s2.r[2];    b2 := s2.r[4];
  720.         
  721.         # determine if screen2 is to left or right of main screen
  722.         if ((r2 = l1) or (l2 = r1)) begin
  723.             if (t1 > t2)
  724.                 Dy := t1 + pDragXY[2];
  725.             else
  726.                 Dy := t2;
  727.             if (l1 < l2)
  728.                 Dx := l2 - hWidth;
  729.             else
  730.                 Dx := l1 - hWidth;
  731.         end;
  732.         
  733.         # must be above or below main screen
  734.         else begin
  735.             if (l1 > l2)
  736.                 Dx := l1;
  737.             else
  738.                 Dx := l2;
  739.             if (t1 < t2)
  740.                 Dy := t2 - hHeight;
  741.             else
  742.                 Dy := t1 - hHeight;
  743.         end;
  744.         
  745.         LogStr("Dragging window across screen borders...");
  746.         returnVal :=  DragWindow(Dx,Dy);
  747.     end;
  748.     else if not (s2)
  749.         failStr := "Note: Cannot drag across screens because the target doesn't have two monitors";
  750.     else
  751.         failStr := "Something not here couldn't DragAcrossScreens";    # - return unsuccessful
  752.         
  753.     if not(returnVal)
  754.         TCSReturn := -1;     # Feature not available
  755.     else
  756.         TCSReturn := 1;
  757.  
  758.     TCSEnd({ 2, global kTCSetUIWindowDrag }, TCSReturn,failStr);
  759.     if(failStr)    
  760.         LogStr(failStr);
  761.     return(returnVal);
  762. end;    # DragAcrossScreens()
  763.  
  764. #########################################################################
  765. #                SizeAcrossScreens(pSpecifier,pDragXY)
  766. #========================================================================
  767. # Author:            NJV
  768. # Description:        If there are two screens present, this task will size
  769. #                    the window specified by <pSpecifier>  (if there's a grow box)
  770. #                    so half of the window is on the first screen and half of
  771. #                    the window is on the second screen.  
  772. # Parameters:        pSpecifier - Descriptor of the window to size.
  773. #                    pDragXY - a list of two co-ordinates (left-top) pixel
  774. #                            to drag window to (i.e.{0,20} to avoid menu bar
  775. #                            on main screen).
  776. # Returns:            1 - successful
  777. #                    0 - unsuccessful
  778. # Examples:            SizeAcrossScreens("myWindow",{0,20}).
  779. # Assumptions:        None
  780. #========================================================================
  781. # History:
  782. # KTA    8/24/93        TCS stack parity check
  783. #########################################################################
  784. TASK SizeAcrossScreens(pSpecifier, pDragXY) 
  785. begin
  786.     # BUG - if second screen is above or below main screen, the following error occurs,
  787.     # but routine still works
  788.     # size [window … ] w: horizontal coordinate off bounds
  789.     returnVal := 0;
  790.     failStr := '';
  791.     # get screen information
  792.     s1 := match [screen m:true]!;
  793.     s2 := match [screen m:false]!;
  794.     
  795.     wind := FindWindow(pSpecifier);
  796.     
  797.     TCSStart({ 2, global kTCSetUIWindowSize }, "SizeAcrossScreens");
  798.     if (s2 and s1 and wind)
  799.     begin            
  800.         # determine smallest size of window's width and height
  801.         SizeWindow(20,20);    # attempt to size to 20,20
  802.         newWind := FindWindow(pSpecifier);
  803.         wWidth := newWind.r[3] - newWind.r[1];
  804.         wHeight := newWind.r[4] - newWind.r[2];
  805.         
  806.         # assign various sides of screens to easier and shorter variables
  807.         l1 := s1.r[1];    r1 := s1.r[3];    t1 := s1.r[2];    b1 := s1.r[4];
  808.         l2 := s2.r[1];    r2 := s2.r[3];    t2 := s2.r[2];    b2 := s2.r[4];    
  809.         
  810.         # determine if screen2 is to left or right of main screen
  811.         if (r2 = l1) begin        # screen 2 is left of screen 1
  812.             Dx := l1 - wWidth;    # put on right edge of window on left edge of screen 2
  813.             
  814.             # calculate top y value of window
  815.             if (t2 > t1) begin    # mid or low left - put at b1 level of screen 2
  816.                 if ((b1 - wHeight) < (t2+wHeight)) begin    # can't be done
  817.                     LogStr("Screen positions do not allow for sizing across 2 monitors");
  818.                     return(ResetWindow(wind));
  819.                 end;
  820.                 Dy := t2;
  821.             end;
  822.             else                # high-left
  823.                 Dy := b2 - wHeight;
  824.             Sy := b1-Dy;
  825.             Sx := wWidth + (r1-l1);
  826.         end;
  827.         
  828.         else if (l2 = r1) begin    # screen 2 is right of screen 1
  829.             Dx := l2 - wWidth;    # put at right of screen 1
  830.             if (t2 > t1)        # mid or low right    
  831.                 Dy := t2 - wHeight;
  832.             else begin            # high right
  833.                 if ((b2 - wHeight) < (t1+wHeight)) begin    # can't be done
  834.                     LogStr("Screen positions do not allow for sizing across 2 monitors");
  835.                     return(ResetWindow(wind));
  836.                 end;
  837.                 Dy := t1 + pDragXY[2];
  838.             end;
  839.             Sy := b2-Dy;
  840.             Sx := wWidth + (r2-l2);
  841.         end;
  842.         
  843.         # must be above or below main screen
  844.         else begin
  845.             if (l1 > l2)
  846.                 Dx := l2;
  847.             else
  848.                 Dx := l1;
  849.             if (t1 < t2) begin        # screen below main screen
  850.                 Dy := t2 - wHeight;
  851.                 Sy := b2-t2+wHeight;
  852.                 Sx := r2 - Dx;
  853.             end;
  854.             else begin                # screen above main screen
  855.                 Dy := t1 - wHeight;
  856.                 Sy := (b1-t1) + wHeight;
  857.                 Sx := r1 - Dx;
  858.             end;
  859.         end;
  860.         
  861.         DragWindow(Dx,Dy);
  862.         LogStr("Sizing window across screen borders...");
  863.         SizeWindow(Sx-1,Sy);
  864.         returnVal := 1;
  865.     end;
  866.     else if not (s2)
  867.         failStr := "Note: Cannot size across screens because the target doesn't have two monitors";
  868.     else
  869.         failStr := "Something not here - couldn't resize across screens";
  870.  
  871.     if not(returnVal)
  872.         TCSReturn := -1;     # Feature not available
  873.     else
  874.         TCSReturn := 1;
  875.  
  876.     TCSEnd({ 2, global kTCSetUIWindowSize }, TCSReturn,failStr);
  877.     if(failStr)
  878.         LogStr(failStr);    
  879.     return(returnVal);
  880. end; # SizeAcrossScreens()
  881.  
  882.  
  883. #########################################################################
  884. #                        AdjustRectToScreen(pTheRect)
  885. #========================================================================
  886. # Author:            Nick Vaccaro
  887. # Description:        This routine checks a rectangle to see if it is within
  888. #                    the screen, if any part of it is not, it will be 
  889. #                    clipped so as to fit the screen.  This is done by
  890. #                    comparing the coordinates of the rectangle with that of 
  891. #                    the screen.  
  892. # Parameters:        pTheRect - holds the coordinates of the rectangle.
  893. # Returns:            pTheRect -     the coordinates of the clipped rectangle.
  894. #                                (if it was not completely within the screen)
  895. #                            or    the coordinates of the original rectangle
  896. #                                (if it lies totally within the screen)
  897. # Examples:            AdjustRectToScreen(Window.r).
  898. # Assumptions:        All windows are no larger than the screen.
  899. #========================================================================
  900. # History:
  901. #
  902. #########################################################################
  903. TASK AdjustRectToScreen(pTheRect) 
  904. begin
  905.     screenList := collect [screen]!;
  906.     screenCount := card screenList;
  907.     if (screenCount = 1) begin                    # only one screen
  908.         screenRect := screenList[1].r;
  909.         Top := pTheRect[2];                        # 'Top' cannot go beyond the title bar
  910.         
  911.         if (pTheRect[1] <= screenRect[1])         # compare left,top,right and bottom
  912.             Left := screenRect[1];                # coordinates with screen coordinates
  913.         else                                
  914.             Left := pTheRect[1];
  915.         if (pTheRect[3] >= screenRect[3])
  916.             Right := screenRect[3];
  917.         else
  918.             Right := pTheRect[3];
  919.         if (pTheRect[4] >= screenRect[4])
  920.             Bottom := screenRect[4];
  921.         else
  922.             Bottom := pTheRect[4]; 
  923.             
  924.         pTheRect :=     {Left,Top,Right,Bottom};
  925.         return(pTheRect);
  926.     end;
  927. end;    # AdjustRectToScreen()
  928.  
  929.  
  930.  
  931. #########################################################################
  932. #                        CoverCompletely(pFirstWindow,pSecondWindow)
  933. #========================================================================
  934. # Author:            SMQ
  935. # Description:        This routine determines whether or not one window 
  936. #                    completely covers another.  This is done by comparing
  937. #                    the coordinates of both windows.  
  938. # Parameters:        pFirstWindow - specifies the first window.
  939. #                    pSecondWindow - specifies the second window.
  940. # Returns:            1 - second window is completely covered by the first.
  941. #                    0 - second window is partially or totally Uncovered.
  942. # Examples:            CoverCompletely(window1,window2).
  943. # Assumptions:        None
  944. #========================================================================
  945. # History:
  946. #
  947. #########################################################################
  948. TASK CoverCompletely (pFirstWindow, pSecondWindow)
  949. begin
  950.     returnVal := 0 ;
  951.     
  952.     firstWindow := FindWindow(pFirstWindow);
  953.     secondWindow := FindWindow(pSecondWindow);
  954.     firstOrd := firstWindow.o;
  955.     firstRect := firstWindow.r;
  956.     secondOrd := secondWindow.o;
  957.     secondRect := secondWindow.r;
  958.     if (firstOrd < secondOrd) begin            # could be covered - let's check
  959.         # first, adjust the rectangles - if required
  960.         Rect2 := AdjustRectToScreen(secondRect);
  961.         Rect1 := AdjustRectToScreen(firstRect);
  962.         returnVal := RectInRect(Rect2,Rect1);
  963.     end;
  964.     return(returnVal);
  965. end;    # CoverCompletely()
  966.  
  967.  
  968.  
  969.  
  970. #########################################################################
  971. #                        ResetWindow(pTheWindow)
  972. #========================================================================
  973. # Author:            Nick Vaccaro
  974. # Description:        Resets the first window with a grow and zoom box to
  975. #                    the size and position of the input parameter wind 
  976. #                    window descriptor.  
  977. # Parameters:        pTheWindow - window descriptor of original window.
  978. # Returns:            0 - error
  979. #                    1 - no error
  980. # Examples:            ResetWindow(pTheWindow).
  981. # Assumptions:        None
  982. #========================================================================
  983. # History:
  984. #
  985. #########################################################################
  986. TASK ResetWindow(pTheWindow) 
  987. begin
  988.     global OrigScrollBars;
  989.     returnVal := 0;
  990.     
  991.     theWind := SelectWindow([window g:true z:true]!);
  992.     if (theWind)
  993.     begin
  994.         windOrd := theWind.o;
  995.         theTitle := theWind.t;
  996.         windRect := theWind.r;
  997.         theDesc := [window t:theTitle o:windOrd]!;# Partial window descriptor contains TITLE and ORD
  998.         
  999.         LogStr("==== Restoring window titled ∂"{theTitle}∂" to original size/location"); 
  1000.         SizeWindow(20,20,theDesc);
  1001.         DragWindow(pTheWindow.r[1],pTheWindow.r[2],theDesc);
  1002.         SizeWindow(pTheWindow.r[3]-pTheWindow.r[1],pTheWindow.r[4]-pTheWindow.r[2],theDesc);
  1003.         if ((not isUndefined(OrigScrollBars)) and (global OrigScrollBars)) 
  1004.         begin
  1005.             vert := OrigScrollBars[1];
  1006.             ScrollWindow('V',vert[1],vert[2]);
  1007.             if (card OrigScrollBars >= 2) begin
  1008.                 horiz := OrigScrollBars[2];    # bug fix 6/27/91
  1009.                 ScrollWindow('H',horiz[1],horiz[2]);
  1010.             end;
  1011.         end;
  1012.         LogStr("==== Done restoring window titled ∂"{theTitle}∂""); 
  1013.         returnVal := 1;
  1014.     end;
  1015.     else
  1016.         Logstr("!@#$% Couldn't select the window");
  1017.     return(returnVal);
  1018. end;    # ResetWindow()
  1019.  
  1020.  
  1021. ########################################################################
  1022. #                        SelectWindow(pSpecifier)
  1023. #=======================================================================
  1024. # Author:        NJV
  1025. # Description:    This routine will select a window specified by
  1026. #                <pSpecifier>.
  1027. # Parameters:    pSpecifier - holds the title or ordinality or window descriptor
  1028. #                            of window to select.
  1029. # Returns:        {theDesc} - Updated window descriptor - Selected window OK
  1030. #                 0 - Couldn't find window to select
  1031. #=======================================================================
  1032. # History:
  1033. # KTA    7/19/93    Updated theDesc so descriptor is not embedded in a list.
  1034. ########################################################################
  1035. TASK SelectWindow(pSpecifier := 0) 
  1036. begin
  1037.     returnVal := 0;            # Init error condition
  1038.     theWind := FindWindow(pSpecifier);
  1039.     if (theWind)
  1040.     begin
  1041.         windOrd := theWind.o;
  1042.         title := theWind.t;
  1043.         windRect := theWind.r;
  1044.         if(windOrd <> 1)
  1045.         begin
  1046.             UnCoverWindow(pSpecifier);
  1047.             select [window o:windOrd t:title]!;
  1048.             Logstr("Selected window of ordinality {windOrd} (titled '{title}')");
  1049.             theDesc := [window t:title r:windRect];        # Call FindWindow with title and rect
  1050.             returnVal := FindWindow(theDesc);            # return the updated window descriptor
  1051.         end;
  1052.         else        # The specified window is already o:1
  1053.             returnVal := theWind;
  1054.     end;
  1055.     else 
  1056.         Logstr("!@#$% Couldn't select the window");
  1057.     return(returnVal);
  1058. end;  # SelectWindow()
  1059.  
  1060.  
  1061. ########################################################################
  1062. #                        UnCoverWindow(pSpecifier, pFrontWindow)
  1063. #=======================================================================
  1064. # Author:        Kevin Avoy
  1065. # Description:    This routine will move a window out of the way if it covers
  1066. #                our desired window.
  1067. # Parameters:    pSpecifier -    holds the title or ordinality of window that is desired.
  1068. #                pFrontWindow - window that is in front of the desired one.
  1069. # Returns:        Nothing
  1070. #=======================================================================
  1071. # History:
  1072. # KTA    7/20/93    Updated window descriptor so it is not contained with in a list.
  1073. ########################################################################
  1074. TASK UnCoverWindow(pSpecifier, pFrontWindow := 0)
  1075. begin
  1076.     returnVal := 0;
  1077.     desiredWindow := FindWindow(pSpecifier);
  1078.     windOrd := desiredWindow.o;
  1079.     theTitle := desiredWindow.t;
  1080.     windRect := desiredWindow.r;
  1081.     theDesc := [window t:theTitle  o:windOrd];
  1082.     if (windOrd <> 1)        # Desired window is not the frontmost window
  1083.     begin                    # target window not frontmost
  1084.          match [screen r:?theScreenRect m:true]!;
  1085.         # See if there is another window in front of it 
  1086.         frontWind := match [window o:?newOrd r:?FRect t:?Front g:true z:true]!;
  1087.         frontDesc := [window t:Front  o:newOrd];
  1088.         if (newOrd < windOrd)
  1089.         begin
  1090.             # see if target window is covered up - if so, uncover
  1091.             coverup := CoverCompletely(frontDesc,theDesc);
  1092.             if (coverup)
  1093.             begin        # move front window aside to show target window
  1094.                 if (windRect[1] <= 0)
  1095.                     DragWindow(20,FRect[2],frontDesc,1);
  1096.                 else if (windRect[3] >= theScreenRect[3])
  1097.                     DragWindow(-20,FRect[2],frontDesc,1);
  1098.                 else 
  1099.                     DragWindow(windRect[1]+20,FRect[2],frontDesc,1);
  1100.             end;
  1101.         end;
  1102.     end;
  1103. end;
  1104.  
  1105. #########################################################################
  1106. #    DragWindow(pHorizontalPixels, pVerticalPixels,pSpecifier,pAbsolutely)
  1107. #========================================================================
  1108. # Author:        Kevin Avoy
  1109. # Description:    This routine will drag the specified window.
  1110. #                <pHorizontalPixels> pixels horizontally (negative drags left) 
  1111. #                and <pVerticalPixels> pixels vertically (negative drags up)
  1112. # Parameters:    pHorizontalPixels - Horizontal pixel offset to drag the window
  1113. #                pVerticalPixels    - Vertical pixel offset to drag the window
  1114. #                pSpecifier - Window specifier
  1115. #                pAbsolutely -    1 if absolute drag
  1116. #                                0 if relative drag
  1117. # Returns:        1 - Dragged window OK
  1118. #                0 - Couldn't find window to drag
  1119. #========================================================================
  1120. # History:
  1121. # KTA    8/24/93        TCS stack parity check
  1122. # KTA    9/21/93        Added a TCSStr to the TCSEnd call, which descibes the action
  1123. #########################################################################
  1124. TASK DragWindow(pHorizontalPixels := "Random", pVerticalPixels := "Random", pSpecifier := 0,pAbsolutely := 1) 
  1125. begin
  1126.     if (global gScreenInset)
  1127.         inset := gScreenInset;
  1128.     else
  1129.         inset := { 0,20,10,10};
  1130.     noErrorFlag := 0;            # Init error condition
  1131.     if (pHorizontalPixels = "Random") or (pHorizontalPixels = "RandomReturn") 
  1132.     begin                                # user wants random coordinates
  1133.         if (pHorizontalPixels = "RandomReturn")
  1134.             RandReturn := 1;
  1135.         xyRandom := getXYRandom(inset);
  1136.         pHorizontalPixels := xyRandom[1];
  1137.         pVerticalPixels := xyRandom[2];
  1138.     end;
  1139.  
  1140.     theWind := FindWindow(pSpecifier);
  1141.     if (theWind) begin
  1142.         windOrd := theWind.o;
  1143.         title := theWind.t;
  1144.  
  1145.         if (pSpecifier > 0)
  1146.             Str1 := "of ordinality {pSpecifier} ";
  1147.         else if (pSpecifier = 0)
  1148.             Str1 := "with grow and zoom box ";
  1149.         else if( not (TypeOf(pSpecifier) = 'integer'))
  1150.             Str1 := "";
  1151.         if (RandReturn)         # Save original coordinates
  1152.         begin
  1153.             origH := theWind.r[1];
  1154.             origV := theWind.r[2];
  1155.         end;            
  1156.         TCSStart({ 1, global kTCSetUIWindowDrag },"DragWindow");        # Start TCS
  1157.         if (pAbsolutely) 
  1158.         begin
  1159.             drag [window o:windOrd t:title]! a:{pHorizontalPixels,pVerticalPixels};                        #To drag the window
  1160.             str := "Dragged window {Str1}titled '{title}' to absolute location ∂({pHorizontalPixels},{pVerticalPixels}∂)";
  1161.             noErrorFlag := 1;
  1162.         end;
  1163.         else 
  1164.         begin
  1165.             drag [window o:windOrd t:title]! r:{pHorizontalPixels,pVerticalPixels};                        #To drag the window
  1166.             str := "Dragged window {Str1}titled '{title}' {pHorizontalPixels} pixels horizontally and {pVerticalPixels} pixels vertically";
  1167.             noErrorFlag := 1;
  1168.         end;
  1169.         TCSEnd({ 1, global kTCSetUIWindowDrag }, noErrorFlag,,,str);
  1170.         LogStr(str);
  1171.         if (RandReturn)             #Move back to original location
  1172.         begin
  1173.             TCSStart({ 3, global kTCSetUIWindowDrag },"DragReturn");        # Start TCS
  1174.             drag [window o:windOrd t:title]! a:{origH,origV};                #To drag the window
  1175.             str := "Dragged window titled '{title}' back to it's original location at ∂({Origh}, {Origv}∂)";
  1176.             TCSEnd({ 3, global kTCSetUIWindowDrag }, noErrorFlag,,,str);
  1177.             LogStr(str);
  1178.         end;
  1179.     end;     
  1180.     return(noErrorFlag);
  1181. end;  # DragWindow()
  1182.  
  1183.  
  1184. #########################################################################
  1185. #                    SizeWindow(pPixelsWide,pPixelsHigh,pSpecifier,pAbsolutely)
  1186. #========================================================================
  1187. # Author:        Kevin Avoy
  1188. # Description:    This routine will match and resize the specified window.
  1189. #                If only the <pPixelsWide> and <pPixelsHigh> parameters are 
  1190. #                passed, the default behavior will size the first window 
  1191. #                containing a grow and zoom box pAbsolutely.  If no parameters
  1192. #                are passed, then the default behavior will generate random
  1193. #                coordinates on the main screen and resize the window
  1194. #                to an absolute size.  If the user passes in the string
  1195. #                "random" for <pPixelsWide> and <pPixelsHigh> and passes 0 for
  1196. #                the pAbsolutely parameter (for a resize relative to current size),
  1197. #                then checks are performed to assure that new size will
  1198. #                not go off of the screen.  If it does, the values will
  1199. #                be adjusted so that the largest the window can be sized
  1200. #                is to the border of the screen.
  1201. # Parameters:    pPixelsWide - the width to resize the window
  1202. #                pPixelsHigh - the height to resize the window
  1203. #                pSpecifier -    title or ordinality of window to be sized
  1204. #                pAbsolutely -    1 if resize window absolute
  1205. #                                0 if resize window relative
  1206. # Returns:        1 - Resized window OK
  1207. #                0 - Couldn't resize window
  1208. # Examples:        SizeWindow(200,400);
  1209. #========================================================================
  1210. # History:
  1211. # KTA    8/24/93        TCS stack parity check
  1212. # KTA    12/16/93    Insure that pixels wide is not smaller than 20.
  1213. #########################################################################
  1214. TASK SizeWindow(pPixelsWide:="random", pPixelsHigh:="random", pSpecifier := 0, pAbsolutely := 1) 
  1215. begin
  1216.     if (global gScreenInset)
  1217.         inset := gScreenInset;
  1218.     else
  1219.         inset := { 20,20,0,0};
  1220.     noErrorFlag := 0;
  1221.     TCSReturn := 0;
  1222.     theWind := FindWindow(pSpecifier);
  1223.     pSpecifier := theWind.o;
  1224.     title := theWind.t;
  1225.     sizeBox := theWind.g;
  1226.     theWindRect := theWind.r;
  1227.  
  1228.     if (theWind) 
  1229.     begin    
  1230.         TCSStart({ 1, global kTCSetUIWindowSize },"SizeWindow");        # Start TCS
  1231.         if (sizeBox)
  1232.         begin
  1233.             randomFlag := 0;
  1234.             if (pPixelsWide = "random")     # user wants to size window randomly
  1235.             begin
  1236.                 if (inset[1] < 20 )                    # Insure that we do not try to size the window to smaller than 20 pixels or 
  1237.                     inset := replace(20,1,inset);    # VU will generate an "Out of bounds error"
  1238.  
  1239.                 xyRandom := getXYRandom(inset);
  1240.                 pPixelsWide := xyRandom[1];
  1241.                 pPixelsHigh := xyRandom[2];
  1242.                 randomFlag := 1;
  1243.                 if (not pAbsolutely)         # relative - include possible negative values
  1244.                 begin
  1245.                     negative := random(0,1);
  1246.                     if (negative = 1) 
  1247.                     begin
  1248.                         pPixelsWide := 0 - pPixelsWide;
  1249.                         pPixelsHigh:= 0 - pPixelsHigh;
  1250.                     end;
  1251.                 end;
  1252.             end;
  1253.             
  1254.             # pSpecifier = ordinality of window to size
  1255.             # title = title of window to size
  1256.             if (randomFlag) # make sure if random numbers were generated that new window size is on screen
  1257.             begin
  1258.                 match [screen r:?theScrnRect]!;
  1259.                 if (pAbsolutely)    # get Top-Left corner coord of window
  1260.                 begin
  1261.                     if ((theWindRect[1] + pPixelsWide) > theScrnRect[3])        # pPixelsWide value off of screen - adjust it
  1262.                         pPixelsWide := theScrnRect[3] - theWindRect[1];
  1263.                     if ((theWindRect[2] + pPixelsHigh) > theScrnRect[4])        # pPixelsHigh value off of screen - adjust it
  1264.                         pPixelsHigh := theScrnRect[4] - theWindRect[2];
  1265.                 end;
  1266.                 else                 # size window relative - get Bottom-Right coord of window
  1267.                 begin
  1268.                     if (not negative) 
  1269.                     begin
  1270.                         if ((theWindRect[3] + pPixelsWide) > theScrnRect[3])        # pPixelsWide value off of screen
  1271.                             pPixelsWide := theScrnRect[3] - theWindRect[3];
  1272.                         if ((theWindRect[4] + pPixelsHigh) > theScrnRect[4])        # pPixelsHigh value off of screen
  1273.                             pPixelsHigh := theScrnRect[4] - theWindRect[4];
  1274.                     end;
  1275.                     ### the 20 in the equations below must be there.  This is to assure that
  1276.                     ### the window is not sized below 20 horizontally (the size box is 20 pixels,
  1277.                     ### and attempts to size smaller than that will cause VU to display an
  1278.                     ### "Out of bounds" error.
  1279.                     else begin        # negative value - must check against upper-left corner of screen
  1280.                         if ((theWindRect[3] + pPixelsWide - 20) < theScrnRect[1])        # pPixelsWide value off of screen
  1281.                             pPixelsWide := 20 - theWindRect[3] - theScrnRect[1];
  1282.                         if ((theWindRect[4] + pPixelsHigh - 20) < theScrnRect[2])        # pPixelsHigh value off of screen
  1283.                             pPixelsHigh := 20 - theWindRect[4] - theScrnRect[2];
  1284.                     end;
  1285.                 end;
  1286.             end;
  1287.             if (pAbsolutely) 
  1288.             begin
  1289.                 size [window t:title o:pSpecifier g:true ] W:pPixelsWide H:pPixelsHigh;                        #To size the window
  1290.                 sizeError := ScriptError();
  1291.                 if not (sizeError)
  1292.                 begin
  1293.                     match [window t:title o:pSpecifier g:true r:?theWindRect]!;
  1294.                     pPixelsWide := theWindRect[3] - theWindRect[1];
  1295.                     pPixelsHigh := theWindRect[4] - theWindRect[2];
  1296.                     str := "Resized window '{title}' absolute {pPixelsWide} pixels wide and {pPixelsHigh} pixels high";
  1297.                     noErrorFlag := 1;
  1298.                 end;
  1299.             end;
  1300.             else 
  1301.             begin
  1302.                 if (randomFlag)                # include negative offsets for random size
  1303.                 begin
  1304.                     match [window t:title o:pSpecifier g:true r:?theOrigWindRect]!;
  1305.         
  1306.                     size [window t:title o:pSpecifier g:true ] r:{ pPixelsWide, pPixelsHigh };                #To size the window
  1307.                     sizeError := ScriptError();
  1308.                     if not (sizeError)
  1309.                     begin
  1310.                         match [window t:title o:pSpecifier g:true r:?theWindRect]!;
  1311.                         pPixelsWide := theWindRect[3] - theOrigWindRect[3];
  1312.                         pPixelsHigh := theWindRect[4] - theOrigWindRect[4];
  1313.                         str := "Resized window '{title}' relative {pPixelsWide} pixels wide and {pPixelsHigh} pixels high";
  1314.                         noErrorFlag := 1;
  1315.                     end;
  1316.                 end;
  1317.                 else 
  1318.                 begin
  1319.                     size [window t:title o:pSpecifier g:true] r:{ pPixelsWide, pPixelsHigh };                        #To size the window
  1320.                     sizeError := ScriptError();
  1321.                     if not (sizeError)
  1322.                     begin
  1323.                         match [window t:title o:pSpecifier g:true r:?theWindRect]!;
  1324.                         pPixelsWide := theWindRect[3] - pPixelsWide;
  1325.                         pPixelsHigh := theWindRect[4] - pPixelsHigh;
  1326.                         str := "Resized window '{title}' relative {pPixelsWide} pixels wide and {pPixelsHigh} pixels high";
  1327.                         noErrorFlag := 1;
  1328.                     end;
  1329.                 end;
  1330.             end;
  1331.         end;    # Is sizeBox
  1332.         else     # No sizeBox
  1333.             sizeError := 1;
  1334.         ##### Error handling for Size window #####
  1335.         if (sizeError)        # if there was no error, failStr = ""
  1336.         begin
  1337.             if(sizeError = -1106)
  1338.             begin
  1339.                 str := "Couldn't size window, SizeBox was off screen (ScriptError = -1106)";
  1340.                 TCSReturn := -1;
  1341.             end;
  1342.             else if(sizeError = -1130)
  1343.                 str := "Couldn't size window, window not active (ScriptError = -1130)";
  1344.             else if(sizeError = 1)
  1345.                 str := "No size box found in window titled '{title}'";
  1346.             else
  1347.                 str := "Couldn't size window, an error occurred while attempting to size to coords ({pPixelsWide},{pPixelsHigh}) - (ScriptError = {sizeError})";
  1348.     
  1349.             TCSInfoStr := "";
  1350.             FailStr := Str;
  1351.         end;
  1352.         else    # No sizeError (sized correctly)
  1353.         begin
  1354.             TCSReturn := noErrorFlag;
  1355.             FailStr := "";
  1356.             TCSInfoStr := "Sized window titled '{title}' to coords ({pPixelsWide},{pPixelsHigh})";
  1357.         end;
  1358.         
  1359.         TCSEnd({ 1, global kTCSetUIWindowSize }, TCSReturn, FailStr,,TCSInfoStr);
  1360.         LogStr(str);
  1361.     end;
  1362.     return(noErrorFlag);    
  1363. end;  # SizeWindow()
  1364.  
  1365.  
  1366. #########################################################################
  1367. #                            ZoomWindow(pSpecifier)
  1368. #========================================================================
  1369. # Author:        Kevin Avoy
  1370. # Description:    Selects the zoom box on the specified window.  If no
  1371. #                parameters are passed, then the default behavior will
  1372. #                zoom the first window with a zoom box.
  1373. # Parameters:    pSpecifier - window specifier
  1374. # Returns:        0 - Couldn't zoom the window
  1375. #                1 - Zoomed the window OK
  1376. #========================================================================
  1377. # History:
  1378. # KTA    8/24/93        TCS stack parity check
  1379. #########################################################################
  1380. TASK ZoomWindow(pSpecifier:= 0) 
  1381. begin
  1382.     noErrorFlag := 0;            # Init error condition
  1383.     TCSReturn := 0;                # Init TCS Return value
  1384.     FailStr := "";                # Init fail string
  1385.     TCSInfoStr := "";
  1386.     theWind := FindWindow(pSpecifier);
  1387.     if theWind begin
  1388.         windOrd := theWind.o;
  1389.         title := theWind.t;
  1390.         zoomBox := theWind.z;
  1391.         theRect := theWind.r;                        # njv - added 6/25/91
  1392.         theHitPoint := {theRect[3]-20,theRect[2]};    # hit point for zoom box
  1393.         hitPointOffScreen := true;
  1394.         
  1395.         if (pSpecifier > 0)
  1396.             Str1 := "of ordinality {pSpecifier} ";
  1397.         else if (pSpecifier = 0)
  1398.             Str1 := "with a zoom box ";
  1399.         else if( not (TypeOf(pSpecifier) = 'integer'))
  1400.             Str1 := "";
  1401.             
  1402.         TCSStart({ 1, global kTCSetUIWindowMiscOp }, "Zoom");                # TCS Start
  1403.         if (zoomBox) 
  1404.         begin
  1405.             zoom [window o:windOrd t:title]!;    #To zoom the window
  1406.             zoomError := ScriptError();
  1407.             
  1408.             if (not zoomError)
  1409.             begin
  1410.                 str := "Zoomed window {Str1}titled '{title}'";
  1411.                 noErrorFlag := 1;            # Success!
  1412.             end;
  1413.         end;
  1414.         else        # No ZoomBox
  1415.             zoomError := 1; 
  1416.  
  1417.         ##### Error handling for Zoom window #####
  1418.         if (zoomError)        # if there was no error, failStr = ""
  1419.         begin
  1420.             if(zoomError = -1106)
  1421.             begin
  1422.                 str := "Couldn't zoom window titled '{title}', ZoomBox was off screen (ScriptError = -1106)";
  1423.                 TCSReturn := -1;
  1424.             end;
  1425.             else if(zoomError = -1130)
  1426.                 str := "Couldn't zoom window titled '{title}', window not active (ScriptError = -1130)";
  1427.             else if(zoomError = 1)
  1428.                 str := "No zoom box found in window {Str1}titled '{title}'";
  1429.             else
  1430.                 str := "Couldn't zoom window titled '{title}', an error occurred (ScriptError = {sizeError})";
  1431.     
  1432.             FailStr := Str;
  1433.         end;
  1434.         else    # No zoomError (zoomed correctly)
  1435.         begin
  1436.             TCSReturn := noErrorFlag;    # Normally this will be a 1 indicating success
  1437.             FailStr := "";                # No FailStr since success
  1438.             TCSInfoStr := "Zoomed window titled '{title}'";
  1439.         end;
  1440.         
  1441.         TCSEnd({ 1, global kTCSetUIWindowMiscOp }, TCSReturn, FailStr,,TCSInfoStr);
  1442.         LogStr(str);
  1443.     end; 
  1444.     return(noErrorFlag);
  1445. end;  # ZoomWindow()
  1446.  
  1447. #########################################################################
  1448. #                CloseWindow(pHowClose, pOverwrite, pSpecifier,pNewDocName)
  1449. #========================================================================
  1450. # Author:        KTA/NJV/DMM
  1451. # Description:    This routine will close the specified window.  If no
  1452. #                parameters are passed to this routine, the default behavior
  1453. #                will select the close box of the first window with a close box.
  1454. # Parameters:    pHowClose -    0 -    tries all three ways noted below to close the
  1455. #                                window (if needed)
  1456. #                            1 -    tries to close window by selecting "Close" menu
  1457. #                                item
  1458. #                            2 -    tries to close window by typing "Close" menu
  1459. #                                item's key equivalent
  1460. #                            3 -    tries to close window by selecting window's
  1461. #                                close box
  1462. #                pOverwrite -    0 -    will select "No" from a save-changes dialog
  1463. #                                if one appears when closing window
  1464. #                            1 -    will select "Yes" to save changes
  1465. #                pSpecifier - window specifier
  1466. #                pNewDocName - string holding new document name - if pOverwrite
  1467. #                            parameter is 1, then pNewDocName will be used for
  1468. #                            naming the file.
  1469. # Returns:        1 - Closed window OK
  1470. #                0 - Couldn't find window to close
  1471. #========================================================================
  1472. # History:
  1473. # KTA    7/19/93        Removed theWind descriptor from being embedded in a list
  1474. # KTA    7/23/93        Added a wait(2) prior to 'Save Document?? check also made
  1475. #                    call to IsStandardFile instead of matching 'DeskTop' button.
  1476. # KTA    8/24/93        TCS stack parity check
  1477. # KTA    12/01/93    Enhanced check if window was closed to also check by the 
  1478. #                     rect of the window. (bug 1120098)
  1479. ###########################################################################
  1480. TASK CloseWindow(pHowClose := 3,pOverWrite := 1,pSpecifier := 0,pNewDocName :="") 
  1481. begin
  1482.     noErrorFlag := 0;
  1483.  
  1484.     theWind := FindWindow(pSpecifier);    # Find the specified window
  1485.     if (theWind) begin                    # IF - we found the window
  1486.         ord := theWind.o;                # make assignments
  1487.         theTitle := theWind.t;
  1488.         theGrow := theWind.g;
  1489.         theZoom := theWind.z;
  1490.         theRect := theWind.r;
  1491.         if (ord <> 1)
  1492.         begin
  1493.             SelectWindow(ord);        # Select the window if it's not the frontmost
  1494.             theWind := FindWindow([window t:theTitle g:theGrow z:theZoom]!);
  1495.             ord := theWind.o;        # Reassign Ord because selection may have changed ordinality
  1496.         end;
  1497.         if (not pHowClose)            # Try all methods until one works
  1498.             pHowClose := {1,2,3};
  1499.         else
  1500.             pHowClose := {pHowClose};    # Just use the specified method
  1501.             
  1502.         numItems := Card(pHowClose);
  1503.         for i := 1 to numItems        # Execute once if way to close is specified 
  1504.         begin                        # otherwise three times attempting all methods
  1505.             closeMethod := pHowClose[i];
  1506.             if (closeMethod = 1) begin        # Close with menu item
  1507.                 TCSNum := 2;
  1508.                 TCSStart({ TCSNum, global kTCSetUIWindowClose }, "CloseFromFileMenu");
  1509.                 if(SelectMenuItem("Close","File"))
  1510.                     noErrorFlag := 1;        # Success
  1511.             end;
  1512.             else if (closeMethod = 2) begin        # Close with key equivelant
  1513.                 closeKey := match[menuItem t:"Close"];
  1514.                 TCSNum := 2;
  1515.                 TCSStart({ TCSNum, global kTCSetUIWindowClose }, "CloseFromKeyEq");
  1516.                 if (closeKey.k) begin
  1517.                     KeyEq(closeKey.k);
  1518.                     noErrorFlag := 1;        # Success
  1519.                 end;
  1520.             end;
  1521.             else if (closeMethod = 3) begin        # Close with close box
  1522.                 TCSNum := 1;
  1523.                 TCSStart({ TCSNum, global kTCSetUIWindowClose }, "CloseBox");
  1524.                 if (theWind.c)
  1525.                 begin
  1526.                     close [window o:ord t:theTitle c:true]!;
  1527.                     LogStr("Selected the close box on window titled '{theTitle}'");
  1528.                     noErrorFlag := 1;        # Success
  1529.                 end;
  1530.                 else
  1531.                     LogStr("Couldn't find the close box on window titled '{theTitle}'");
  1532.             end;
  1533.     
  1534.             if (noErrorFlag)             # IF - we had a success        
  1535.                 i := numItems;            # break because window should be closed
  1536.         end;
  1537.  
  1538.         if (noErrorFlag)                  # IF - we had a success    
  1539.         begin
  1540.             wait(2);                    # Wait to allow dialog to appear
  1541.             if(checkYesNo(pOverWrite))    # Check if a 'Save Document??' dialog appeared
  1542.             begin
  1543.                 if(pOverWrite)            # if the dialog appeared and we want to save 
  1544.                 begin
  1545.                     if (IsStandardFile())        # check for Standard File
  1546.                     begin
  1547.                         SaveAs(pNewDocName,true);
  1548.                         theTitle := Global gLastSavedFile;
  1549.                     end;
  1550.                 end;
  1551.             end;
  1552.         end;
  1553.  
  1554.         if(match [window t:theTitle r:theRect]!)         # Is the window we just closed still open
  1555.         begin
  1556.             LogStr("!@#$% Sorry, the window - {theTitle} is still open");
  1557.             noErrorFlag := 0;
  1558.         end;
  1559.         TCSEnd({ TCSNum, global kTCSetUIWindowClose }, noErrorFlag);                # End TCS
  1560.     end;
  1561.     return(noErrorFlag);                # Return Result
  1562. end; # CloseWindow()
  1563.  
  1564.  
  1565. ########################################################################
  1566. #                            ScrollWindow(pWhichScrollBar,pDesirePosition,pMaxPosition)
  1567. #=======================================================================
  1568. # Author:        KTA/NJV
  1569. # Description:    This routine will scroll the specified scrollbar on
  1570. #                the active window.
  1571. # Parameters:    pWhichScrollBar = 'H' - for horizontal scrollbar
  1572. #                                = 'V' - for vertical scrollbar
  1573. #                <pDesirePosition><pMaxPosition> = the fraction pDesirePosition/pMaxPosition
  1574. # Returns:        0 - Couldn't scroll the scroll bar
  1575. #                1 - Scrolled the scroll bar
  1576. # Examples:        ScrollWindow('H',1,2)  will scroll the horizontal bar 1/2
  1577. # Assumptions:    That the scrollbars are present. This routine collects
  1578. #                only the first two scroll bars, which are assumed to be 
  1579. #                the horizontal and vertical scroll bars. 
  1580. #                This routine is not 100% reliable.
  1581. #=======================================================================
  1582. # History:
  1583. # KTA    8/24/93        TCS stack parity check
  1584. # KTA    9/10/93        Better check to see if scroll bars are on screen
  1585. #########################################################################
  1586. TASK ScrollWindow(pWhichScrollBar,pDesirePosition:=-1,pMaxPosition:=-1) 
  1587. begin
  1588.     returnVal := 0;
  1589.     failStr := '';
  1590.     theScrollBars := GetVHScrollBars();
  1591.     theScreen := match[screen];
  1592.     if (theScrollBars)
  1593.     begin
  1594.         vertical := theScrollBars[1];
  1595.         verticalDiff := vertical.s;
  1596.         horizontal := theScrollBars[2];
  1597.         horizontalDiff := horizontal.s;
  1598.  
  1599.         if (pWhichScrollBar = 'V') or (pWhichScrollBar = 'v') 
  1600.         begin
  1601.             if (pDesirePosition=-1) or (pMaxPosition=-1)     # generate random value
  1602.             begin
  1603.                 pDesirePosition := random(0,verticalDiff[2]);
  1604.                 pMaxPosition := verticalDiff[2];
  1605.             end;
  1606.             TCSNum := 1;
  1607.             TCSStart({ TCSNum, global kTCSetUIWindowScroll },"VerticalScroll");        # Start TCS
  1608.             if not(vertical.s = {0,0}) #Test to see if Scrollbars are enabled
  1609.             begin
  1610.                 if (vertical.e)         #Test to see if Scrollbars are enabled
  1611.                 begin
  1612.                     if(vertical.r[1] < theScreen.r[3])
  1613.                     begin
  1614.                         scroll vertical a:{pDesirePosition,pMaxPosition};
  1615.                         scrollError := ScriptError();
  1616.                         if not (scrollError)
  1617.                         begin
  1618.                             LogStr("Scrolled the vertical scroll bar Absolute ({pDesirePosition}, {pMaxPosition})");
  1619.                             returnVal := 1;
  1620.                         end;
  1621.                     end;
  1622.                     else
  1623.                     begin
  1624.                         LogStr("!@#$% The vertical scroll bar is off the screen");
  1625.                         failStr := "!@#$% The vertical scroll bar is off the screen";
  1626.                     end;
  1627.                 end;
  1628.                 else
  1629.                 begin
  1630.                     LogStr("!@#$% The vertical scroll bar was not enabled to scroll");
  1631.                     failStr := "!@#$% The vertical scroll bar was not enabled to scroll";
  1632.                 end;
  1633.             end;
  1634.             else
  1635.             begin
  1636.                 LogStr("!@#$% The vertical scroll bar was not enabled to scroll - no thumbnail");
  1637.                 failStr := "!@#$% The vertical scroll bar was not enabled to scroll - no thumbnail";
  1638.             end;
  1639.         end;
  1640.         else 
  1641.         begin
  1642.             if (pDesirePosition=-1) or (pMaxPosition=-1)     # generate random value
  1643.             begin
  1644.                 pDesirePosition := random(0,horizontalDiff[2]);
  1645.                 pMaxPosition := horizontalDiff[2];
  1646.             end;
  1647.             TCSNum := 2;
  1648.             TCSStart({ TCSNum, global kTCSetUIWindowScroll },"HorizontalScroll");        # Start TCS
  1649.             if not(horizontal.s = {0,0}) #Test to see if Scrollbars are enabled
  1650.             begin
  1651.                 if (horizontal.e)         #Test to see if Scrollbars are enabled
  1652.                 begin
  1653.                     if(horizontal.r[2] < theScreen.r[4])
  1654.                     begin
  1655.                         scroll horizontal a:{pDesirePosition,pMaxPosition};
  1656.                         scrollError := ScriptError();
  1657.                         if not (scrollError)
  1658.                         begin
  1659.                             LogStr("Scrolled the horizontal scroll bar absolute ({pDesirePosition}, {pMaxPosition})");
  1660.                             returnVal := 1;
  1661.                         end;
  1662.                     end;
  1663.                     else
  1664.                     begin
  1665.                         LogStr("!@#$% The horizontal scroll bar is off the screen");
  1666.                         failStr := "!@#$% The horizontal scroll bar is off the screen";
  1667.                     end;
  1668.                 end;
  1669.                 else
  1670.                 begin
  1671.                     LogStr("!@#$% The horizontal scroll bar was not enabled to scroll");
  1672.                     failStr := "!@#$% The horizontal scroll bar was not enabled to scroll";
  1673.                 end;
  1674.             end;
  1675.             else
  1676.             begin
  1677.                 LogStr("!@#$% The horizontal scroll bar was not enabled to scroll - no thumbnail");
  1678.                 failStr := "!@#$% The horizontal scroll bar was not enabled to scroll - no thumbnail";
  1679.             end;
  1680.         end;
  1681.         if(scrollError)
  1682.         begin
  1683.             if (scrollError = -1150)
  1684.                 failStr := failstr + "Couldn't scroll because the scroll bar is off the screen";
  1685.         end;
  1686.         if not(returnVal)
  1687.             TCSReturn := -1;     # Feature not available
  1688.         else
  1689.             TCSReturn := 1;
  1690.     
  1691.         TCSEnd({ TCSNum, global kTCSetUIWindowScroll }, TCSReturn,failStr);
  1692.     end;
  1693.     return(returnVal);
  1694. end;  # ScrollWindow()
  1695.  
  1696. ########################################################################
  1697. #                            GetVHScrollBars()
  1698. #=======================================================================
  1699. # Author:            NJV
  1700. # Description:        This routine will return the vertical and horizontal
  1701. #                    scroll bars.
  1702. # Parameters:        None
  1703. # Returns:            0 - Couldn't find scroll bars
  1704. #                    {vertical,horizontal} - list of vertical and horizontal
  1705. #                                            scroll bars
  1706. # Examples:            scrollBars := GetVHScrollBars();
  1707. # Assumptions:        Top of vertical scroll bar is at a lower vertical value
  1708. #                    that the horizontal (i.e. the top of vertical rect is smaller
  1709. #                    than the top of the horizontal scroll bar's rect).
  1710. #=======================================================================
  1711. # History:
  1712. #
  1713. #########################################################################
  1714. TASK GetVHScrollBars() begin
  1715.     ScrollWindowlist :=collect[scrollbar];
  1716.     if not (card(ScrollWindowlist)) begin
  1717.         LogStr("!@#$% There were no recognizable scroll bars present");
  1718.         return(0);
  1719.     end;
  1720.     Rec1 := ScrollWindowlist[1];
  1721.     Rec2 := ScrollWindowlist[2];
  1722.     Rec1R := Rec1.r[1];
  1723.     Rec2R := Rec2.r[1];
  1724.  
  1725.     if (Rec1R < Rec2R) begin         #To determine which scroll bar is Vertical/Horizontal
  1726.         horizontal := Rec1;
  1727.         vertical := Rec2;
  1728.     end;
  1729.     else begin
  1730.         horizontal := Rec2;
  1731.         vertical := Rec1;
  1732.     end;
  1733.     return({vertical,horizontal});
  1734. end;
  1735.  
  1736. #########################################################################
  1737. #                         CloseAllWindows()
  1738. #=======================================================================
  1739. # Author:          ML
  1740. # Description:    Closes all windows having a close box.
  1741. # Parameters:    None
  1742. # Returns:        Nothing
  1743. # Assuptions:    Windows have close boxes.
  1744. #=======================================================================
  1745. # History:
  1746. #
  1747. ########################################################################
  1748. TASK CloseAllWindows()
  1749. begin
  1750.     KeepGoingFlag := 1;
  1751.     While (KeepGoingFlag)
  1752.     begin
  1753.         if FindWindow([window c:true]!)
  1754.             KeepGoingFlag:= CloseWindow(,,[window c:true]!);
  1755.         else
  1756.             KeepGoingFlag:=0;
  1757.     end;
  1758. end;
  1759.  
  1760.  
  1761. #########################################################################
  1762. #                            FindWindow(pSpecifier)
  1763. #========================================================================
  1764. # Author:        DM
  1765. # Description:    FindWindow will return the descriptor of the window
  1766. #                specified by the parameter pSpecifier.
  1767. # Parameters:    pSpecifier - if string, then it holds title of window
  1768. #                            if integer, then it holds ordinality of window
  1769. #                            if rect, create a fake window specfier with the
  1770. #                                rect as the wind.r
  1771. #                            if window descriptor will match window meeting 
  1772. #                            the specified traits e.g. [window t:'Mywind' o:2]
  1773. #                            Pass 0 to get the first document window
  1774. # Returns:        0 - Couldn't find the window
  1775. #                descriptor - Window descriptor that meets the specified match
  1776. #                            for <pSpecifier>
  1777. # Example:        FindWindow(1);
  1778. #========================================================================
  1779. # History:
  1780. # KTA    7/19/93    Added support for pSpecifier type 'descriptor' removed embedding into list.
  1781. #########################################################################
  1782. TASK FindWindow(pSpecifier := "None") 
  1783. begin
  1784.     #Println "This is pSpecifier from FindWindow - ", pSpecifier;
  1785.     if(pSpecifier = "None") 
  1786.     begin
  1787.         LogStr("Null pSpecifier passed as a parameter to FindWindow");
  1788.         theDesc := [];
  1789.     end;
  1790.     WindType := TypeOf(pSpecifier);
  1791.  
  1792.     if (WindType = 'descriptor')
  1793.         theDesc := match pSpecifier!;
  1794.     else if (WindType = 'string') or (WindType = 'regularExpression')
  1795.     begin
  1796.         theDesc := match [window t:pSpecifier]!;
  1797.         if (not theDesc) 
  1798.         begin
  1799.             LogStr("!@#$% Couldn't match a window of title {pSpecifier}");
  1800.             theDesc := [];
  1801.         end;
  1802.     end;
  1803.     else if(WindType = 'integer') 
  1804.     begin
  1805.         if(pSpecifier > 0) 
  1806.         begin
  1807.             theDesc := match[window o:pSpecifier]!;
  1808.             if (not theDesc) begin
  1809.                 LogStr("!@#$% Couldn't match a window of ordinality {pSpecifier} with a grow box");
  1810.                 theDesc := [];
  1811.             end;
  1812.         end;
  1813.         else 
  1814.         begin
  1815.             if(pSpecifier = 0) 
  1816.             begin
  1817.                 theDesc := match[window c:true g:true]!;
  1818.                 if (not theDesc) 
  1819.                 begin
  1820.                     LogStr("!@#$% Couldn't match a window with a close and grow box");
  1821.                     theDesc := [];
  1822.                 end;
  1823.             end;
  1824.             else 
  1825.             begin
  1826.                 if (pSpecifier < 0) 
  1827.                 begin
  1828.                     scrList := collect[screen]!;
  1829.                     theDesc := scrList[-pSpecifier];
  1830.                     if (not theDesc) 
  1831.                     begin
  1832.                         scrOrd:=-pSpecifier;
  1833.                         LogStr("!@#$% Couldn't match a screen with ordinality {scrOrd}");
  1834.                         theDesc := [];
  1835.                     end;
  1836.                 end;
  1837.             end;
  1838.         end;
  1839.     end;
  1840.     else if(WindType = 'list')
  1841.     begin
  1842.         if((TypeOf(pSpecifier[1]) = 'integer'))
  1843.         begin
  1844.             theDesc := [window r:pSpecifier t:"RECTANGLE" o:0];
  1845.             LogStr("Faked out FindWindow with a rectangle!!");
  1846.         end;
  1847.         else            # the old way was e.g.FindWindow({[window t:'Untitled']});
  1848.         begin
  1849.             println "    +++++++++ Error: Its an old FindWindow() Descriptor";
  1850.             #theDesc := match pSpecifier[1];
  1851.         end;
  1852.     end;
  1853.     #Println "This is theDesc from FindWindow - ", theDesc;
  1854.     return (theDesc);
  1855. end; # FindWindow()
  1856.  
  1857.  
  1858. ########################################################################
  1859. #        GetRandomPointsRelativeToWindow(pInset, pSpecifier, pNumPts)
  1860. #=======================================================================
  1861. # Author:             Kevin Avoy
  1862. # Description:        Determines what the rectangle is for the window specified 
  1863. #                    as Specifier and returns a random X and Y coordinate which
  1864. #                    will be inside the window if moving relative to the top 
  1865. #                    left corner of the screen or window.
  1866. # Parameters:        pInset - ltrb inset from screen or window
  1867. #                    pSpecifier
  1868. #                            Integer
  1869. #                              > 0 - Ordinality window to find coords in
  1870. #                              = O coords in window with s:doc g:true and c:true
  1871. #                              < 0 coords in specified screen.  Screen numbers
  1872. #                                are negative of pSpecifier.
  1873. #                            String
  1874. #                                title of window to find coords in
  1875. #                            {List}
  1876. #                                any partial or complete window descriptor
  1877. # Returns:            myPoints - List of random X and Y.  eg. { x, y }
  1878. #=======================================================================
  1879. ########################################################################
  1880. TASK GetRandomPointsRelativeToWindow(pInset := { 0,20,20,20}, pSpecifier := 0, pNumPts := 1)
  1881. begin
  1882.     theDesc := FindWindow(pSpecifier);
  1883.     if(theDesc) 
  1884.     begin
  1885.         windowRect := theDesc.r;
  1886.         myPoints := GetXYRandom(pInset, windowRect, pNumPts);
  1887.     end;
  1888.     return(myPoints);
  1889. end;
  1890.  
  1891.  
  1892. #=======================================================================
  1893. # Dialog related tasks:
  1894. #=======================================================================
  1895.  
  1896. #########################################################################
  1897. #                        SelectButton(pButton)
  1898. #========================================================================
  1899. # Author:        KTA
  1900. # Description:    This routine will select the button named <pButtonName>
  1901. # Parameters:    pButton - string - holding name of button to select
  1902. #                            integer - ordinality of Button
  1903. # Returns:        0 - Couldn't select button
  1904. #                pButtonName - Selected button OK
  1905. #========================================================================
  1906. # History:
  1907. # KTA    7/6/93    Performance support: Call (gBeginTimer);
  1908. # KTA    9/13/93 Added support for selecting Buttons for by ordinality
  1909. # KTA    9/21/93 Changed gBeginTimer to gPreSelectButtonHook
  1910. # KTA    9/21/93 Changed gBeginTimer to gPreSelectButtonHook
  1911. # KTA    11/12/93 Changed select[button] to move over the button then click 
  1912. #                 for performance - doesn't require additional match. This
  1913. #                is done to reduce the amount of VU overhead required in matching
  1914. #                the button.
  1915. # KTA    11/16/93 Do logging prior to actually selecting button for performance. 
  1916. # KTA    12/01/93 Added support for button descriptors. 
  1917. #########################################################################
  1918. TASK SelectButton(pButton) 
  1919. begin
  1920.     returnVal := 0;
  1921.     ParameterType := typeOf(pButton);
  1922.     if (ParameterType = 'string')
  1923.         IsButton := match[button t:pButton]!;
  1924.     else if (ParameterType = 'integer')
  1925.         IsButton := match [button o:pButton]!;
  1926.     else if (ParameterType = 'descriptor')
  1927.     begin
  1928.         if(DescType(pButton) = 'button')
  1929.             IsButton := match pButton!;
  1930.         else
  1931.             logStr("!@#$% The descriptor '{pButton}' is not a valid button descriptor");
  1932.     end;
  1933.         
  1934.     if (IsButton)
  1935.     begin
  1936.         theButtonTitle := IsButton.t;
  1937.         if (IsButton.e) 
  1938.         begin
  1939.             LogStr( "Selecting button titled '{theButtonTitle}'");
  1940.             move a:{((IsButton.r[1]+IsButton.r[3])/2),((IsButton.r[2]+IsButton.r[4])/2)};
  1941.             if (global gPreSelectButtonHook)
  1942.                 Call(gPreSelectButtonHook);
  1943.             click;
  1944.             #Select [button t:theButtonTitle]!;
  1945.             returnVal := theButtonTitle;
  1946.         end;
  1947.         else 
  1948.             LogStr("!@#$% Couldn't select button named '{theButtonTitle}' because it's not enabled");
  1949.     end;
  1950.     else
  1951.         LogStr("!@#$% There was no button specified by '{pButton}'");
  1952.  
  1953.     return(returnVal);
  1954. end; # SelectButton()
  1955.  
  1956. #######################################################################
  1957. #                    SelectRadioButton(pRadioButton)
  1958. #========================================================================
  1959. # Author:        KTA
  1960. # Description:    This routine will select RadioButton named <pRadioButtonName>
  1961. # Parameters:    pRadioButton - string - name of radio button to select
  1962. #                                integer - radio button ordinality
  1963. # Returns:        0 - Couldn't select radio button
  1964. #                pRadioButtonName - Selected button OK
  1965. #========================================================================
  1966. # History:
  1967. # KTA    9/13/93 Added support for selecting radioButtons for by ordinality
  1968. #########################################################################
  1969. TASK SelectRadioButton(pRadioButton) 
  1970. begin
  1971.     returnVal := 0;
  1972.     if (typeOf(pRadioButton) = 'string')
  1973.         IsRadioButton := match [RadioButton t:pRadioButton]!;
  1974.     else if (typeOf(pRadioButton) = 'integer')
  1975.         IsRadioButton := match [RadioButton o:pRadioButton]!;
  1976.         
  1977.     if (IsRadioButton) 
  1978.     begin
  1979.         theRadioButtonTitle := IsRadioButton.t;
  1980.         if (IsRadioButton.e) 
  1981.         begin
  1982.             Select [RadioButton t:theRadioButtonTitle];
  1983.             str := "Selected radio button titled '{theRadioButtonTitle}'";
  1984.             returnVal := theRadioButtonTitle;
  1985.         end;
  1986.         else
  1987.             str := "!@#$% Couldn't select radio button named '{theRadioButtonTitle}' because it's not enabled";
  1988.     end;
  1989.     else
  1990.         str := "!@#$% There was no radio button specified by '{pRadioButton}'";
  1991.  
  1992.     LogStr(str);
  1993.     return(returnVal);
  1994. end; # SelectRadioButton()
  1995.  
  1996. #########################################################################
  1997. #                        SelectCheckBox(pCheckBox)
  1998. #========================================================================
  1999. # Author:        KTA
  2000. # Description:    This routine will select CheckBox named <pCheckBoxName>
  2001. # Paramters:    pCheckBox - string - name of check box to select
  2002. #                            integer - ordinality of checkBox
  2003. # Returns:        0 - Couldn't select check box
  2004. #                pCheckBoxName - Selected check box OK
  2005. #========================================================================
  2006. # History:
  2007. # KTA    9/13/93 Added support for selecting CheckBox for by ordinality
  2008. #########################################################################
  2009. TASK SelectCheckBox(pCheckBox) 
  2010. begin
  2011.     returnVal := 0;
  2012.     if (typeOf(pCheckBox) = 'string')
  2013.         isSelectCheckBox := match [CheckBox t:pCheckBox]!;
  2014.     else if(typeOf(pCheckBox) = 'integer')
  2015.         isSelectCheckBox := match [CheckBox o:pCheckBox]!;
  2016.  
  2017.     if (isSelectCheckBox)
  2018.     begin
  2019.         theCheckBoxTitle := isSelectCheckBox.t;
  2020.         if (isSelectCheckBox.e)
  2021.         begin
  2022.             Select [CheckBox t:theCheckBoxTitle];
  2023.             str := "Selected check box titled '{theCheckBoxTitle}'";
  2024.             returnVal := theCheckBoxTitle;
  2025.         end;
  2026.         else 
  2027.             str := "!@#$% Couldn't select check box named '{theCheckBoxTitle}' because it's not enabled";
  2028.     end;
  2029.     else
  2030.         str := "!@#$% There was no check box specified by '{pCheckBox}'";
  2031.  
  2032.     LogStr(str);
  2033.     return(returnVal);
  2034. end; # SelectCheckBox()
  2035.  
  2036.  
  2037. #########################################################################
  2038. #                CheckYesNo(pFlag)
  2039. #========================================================================
  2040. # Author:        SL
  2041. # Description:    Checks for dialog boxes with "Yes" (or "OK") and "No"
  2042. #                buttons. If they are found, clicks one of the buttons
  2043. #                depending on the 'pFlag' parameter.
  2044. # Parameters:    pFlag -    TRUE - Selects "Yes"  or "OK" button.
  2045. #                        FALSE - Selects "No" button.
  2046. #                DocName - Name that docment will be saved with.
  2047. # Returns:        What is returned by SelectButton
  2048. #========================================================================
  2049. # History:
  2050. #
  2051. #########################################################################
  2052. TASK CheckYesNo(pFlag := true)
  2053. begin
  2054.     if ( pFlag )  begin
  2055.         yesBtn := match[button t:"Yes" w:[window o:1]]!;
  2056.         okBtn  := match[button t:"Ok"  w:[window o:1]]!;
  2057.         saveBtn := match[button t:"Save"  w:[window o:1]]!;
  2058.     
  2059.         if (yesBtn)
  2060.             return(SelectButton("Yes"));
  2061.         else if (okbtn)
  2062.             return(SelectButton("OK"));
  2063.         else if (saveBtn)
  2064.             return(SelectButton("Save"));
  2065.     end;
  2066.     else
  2067.     begin
  2068.         noBtn  := match[button t:"No"  w:[window o:1]]!;
  2069.         if (noBtn)
  2070.             return(SelectButton("No"));
  2071.         else
  2072.         begin
  2073.             DontSaveBtn  := match[button t:"Don’t Save"  w:[window o:1]]!;
  2074.             if (DontSaveBtn)
  2075.                 return(SelectButton("Don’t Save"));
  2076.         end;
  2077.     end;
  2078. end; # CheckYesNo()
  2079.  
  2080. ########################################################################
  2081. #        DialogCheck(pFindStaticText,pCommitButton, pLogIT, pWindowDesc)
  2082. #=======================================================================
  2083. # Author:        Kevin Avoy
  2084. # Description:    This routine will to match a dialog of specified by <pWindowDesc>,
  2085. #                with static text - <pFindStaticText>, if found it will select the 
  2086. #                Button - {pCommitButton}. If <pFindStaticText> is not defined a
  2087. #                match will be made on any dialog with static text.
  2088. # Parameters:    pFindStaticText - Static text string that you want to match
  2089. #                pCommitButton   - Button to select if the static text is found.
  2090. #                pLogIT - If you don't want to log the dialog pass 0
  2091. #                pWindowDesc - window descriptor of dialog
  2092. # Returns:        <Static Text> - the Static Text String found pFindStaticText 
  2093. #                and selected pCommitButton
  2094. #                0 - Couldn't find pFindStaticText
  2095. #=======================================================================
  2096. # History:
  2097. # KTA    7/6/93    Changed default pWindowDesc so it doesn't include c:False
  2098. # KTA    11/11/93    Updated so if pFindStaticText = '' it will not need to be a substring
  2099. # KTA    11/15/93    Moved ! in collect statement so it would actually work
  2100. # KTA    12/01/93    Added support for button descriptors
  2101. ########################################################################
  2102. TASK DialogCheck(pFindStaticText :='', pCommitButton :="", pLogIT := 1, pWindowDesc := [window o:1 c:false]) 
  2103. begin
  2104.     returnVal := 0;
  2105.     DialogWin :=  collect[staticText w:pWindowDesc]!; 
  2106.     if (DialogWin) 
  2107.     begin
  2108.         NumStaticItems:= card (DialogWin);
  2109.         for i:= 1 to NumStaticItems 
  2110.         begin
  2111.             StaticItem:= DialogWin[i];
  2112.             theStaticText :=  StaticItem.t;
  2113.             if not( theStaticText = '') 
  2114.             begin
  2115.                 if((IsSubString(pFindStaticText, theStaticText)) or (pFindStaticText = ''))
  2116.                 begin
  2117.                     if (pLogIT) 
  2118.                         LogStr("Found Dialog: '{theStaticText}'");
  2119.                     if (pCommitButton)
  2120.                     begin
  2121.                         ParameterType := typeOf(pCommitButton);
  2122.  
  2123.                         if ((ParameterType = 'string') or (ParameterType = 'descriptor'))
  2124.                             SelectButton(pCommitButton);
  2125.                         else if (pCommitButton = 1)
  2126.                             SpecialKey(returnKey, "Return Key");
  2127.                         else
  2128.                             LogStr('!@#$% Method of dismissing Dialog was not valid');
  2129.                     end;
  2130.                     returnVal := theStaticText;
  2131.                     NumStaticItems:=i;
  2132.                 end; # if(IsSubString(pFindStaticText, theStaticText)) 
  2133.             end; # if not( theStaticText = '') 
  2134.         end; # i:= 1 to NumStaticItems 
  2135.     end; # if (DialogWin) 
  2136.     else 
  2137.         returnVal := 0;
  2138.     return(returnVal);
  2139. end;  # DialogCheck()
  2140.  
  2141.  
  2142. #########################################################################
  2143. #                        DialogHandler(pSpecifier)
  2144. #========================================================================
  2145. # Author:        GS (x25506)
  2146. # Description:    Handle dialog exceptions.
  2147. # Parameters:    pSpecifier - dialog descriptor.
  2148. # Returns:        0 - Unsuccessful
  2149. #                (non-zero) - Successful
  2150. # Examples:        DialogHandler();
  2151. # Assumptions:    None 
  2152. #========================================================================
  2153. # History:
  2154. # KTA    7/27/93    DoubleCheck for dialog because dialogCheck() will only work 
  2155. #                if there is statictext
  2156. #########################################################################
  2157. TASK DialogHandler(pSpecifier := [window o:1 c:false]!)
  2158. begin
  2159.     if (global gDialogHandling)
  2160.     begin
  2161.         tempGAppVer := global gAppVerify;
  2162.         gAppVerify := 0;
  2163.         counter := 0;
  2164.         DialogString := "";
  2165.         returnVal := 0; 
  2166.         myDialogString := "";
  2167.         SpecifiedDialog := FindWindow(pSpecifier);
  2168.         GenericDialog:= FindWindow([window o:1 s:dialog]);    # GenericDialog
  2169.  
  2170.         if((SpecifiedDialog) or (GenericDialog))
  2171.         begin
  2172.             if (match[button t:"Cancel"])
  2173.                 TempDialogStr := DialogCheck(,"Cancel",,pSpecifier);
  2174.             else 
  2175.                 TempDialogStr := DialogCheck(,1,,pSpecifier);
  2176.             
  2177.             if (TempDialogStr)
  2178.             begin
  2179.                 myDialogString := "Dialog := '{TempDialogStr}'";
  2180.                 DialogString := DialogString + " / " + myDialogString;
  2181.                 returnVal := DialogString;
  2182.             end;
  2183.             else
  2184.                 returnVal := DismissDialog(1, pSpecifier);
  2185.         end;            
  2186.         else
  2187.         begin
  2188.             #logstr ("There wasn't any dialogs to dismiss");
  2189.             returnval:= -1;        # Since there is no dialog to dismiss we were successful
  2190.         end;
  2191.  
  2192.         gAppVerify := tempGAppVer;
  2193.         
  2194.         return (returnVal);
  2195.     end;
  2196. end; # DialogHandler()
  2197.  
  2198. #########################################################################
  2199. #                     DismissDialog(pHowToDismiss, pSpecifier)
  2200. #=======================================================================
  2201. # Author:              ML
  2202. # Description:        Generic dialog dismisser.
  2203. # Assumptions:        Window is style dialog and ordinality 1.
  2204. # Parameters:        pHowToDismiss -    1    type return key
  2205. #                                {string} select button named {string}        
  2206. # Returns:            0 - dialog not dismissed
  2207. #                    1 - dialog sucessfully dismissed
  2208. # Example:            DismissDialog ('Cancel')
  2209. #=======================================================================
  2210. # History:
  2211. # KTA    7/6/93    Added default value for the pHowToDismiss input parameter
  2212. # KTA    7/7/93    Changed check to see if it actually dismissed the right dialog
  2213. # KTA    7/19/93    changed pSpecifier so descriptor is not contained in a list
  2214. # KTA    9/13/93    Added support for KeyEq('.') & better check to verfiy dialog 
  2215. #                was dismissed.
  2216. #########################################################################
  2217. TASK DismissDialog (pHowToDismiss := 1, pSpecifier := [window o:1 c:false]!)
  2218. begin
  2219.     returnval:=0;
  2220.     SpecifiedDialog:= FindWindow( pSpecifier);
  2221.     if not (SpecifiedDialog)
  2222.         SpecifiedDialog := FindWindow([window o:1 s:dialog]);    # GenericDialog
  2223.  
  2224.     if (SpecifiedDialog)
  2225.     begin
  2226.         if (pHowToDismiss = 1)
  2227.             SpecialKey(returnKey , "Return Key");
  2228.         else if (TypeOf(pHowToDismiss) = 'string')
  2229.         begin
  2230.             if (pHowToDismiss = '.')
  2231.                 keyEq('.');
  2232.             else
  2233.                 selectbutton (pHowToDismiss);
  2234.         end;
  2235.         
  2236.         wait(2);        ## Give Dialog time to disappear    
  2237.         ## Check to see if dialog is still present
  2238.         
  2239.         if not ((match[window t:SpecifiedDialog.t r:SpecifiedDialog.r c:SpecifiedDialog.c g:SpecifiedDialog.g z:SpecifiedDialog.z]!))
  2240.         begin
  2241.             logstr('Dismissed dialog');
  2242.             returnval:=1;
  2243.         end;
  2244.         else
  2245.             logstr('Unable to dismiss dialog');
  2246.     end; # if SpecifiedDialog
  2247.     else
  2248.     begin
  2249.         logstr ('No dialog to dismiss');
  2250.         returnval:=1;        # Since there is no dialog to dismiss we were successful
  2251.     end;
  2252.     return(returnVal);
  2253. end; # DismissDialog()
  2254.  
  2255.  
  2256.  
  2257. #=======================================================================
  2258. # Mouse action related tasks:
  2259. #=======================================================================
  2260.  
  2261.  
  2262. #########################################################################
  2263. # MoveRelativeToWindow(pHorizontalPixels, pVerticalPixels, pSpecifier,pMouseDown,pInset)
  2264. #========================================================================
  2265. # Author:        NJV
  2266. # Description:    This routine will calculate the window's rectangle
  2267. #                and add pHorizontalPixels and pVerticalPixels input parameters  
  2268. #                to the rectangle's top-left coordinate point.  It will then
  2269. #                move the mouse to that location.  The window is
  2270. #                specified by the pSpecifier input parameter.  If the
  2271. #                pSpecifier parameter is not present, the default
  2272. #                behavior will move relative to the frontmost document window.
  2273. # Parameters:    pHorizontalPixels - int representing left (pHorizontalPixels) coord 
  2274. #                    or List of points.
  2275. #                pVerticalPixels - int representing top (pVerticalPixels) coord
  2276. #                pSpecifier - holds title or ordinality of window
  2277. #                            0 matches first s:document c:true g:true window
  2278. #                pMouseDown - 0 - don't hold mouse key down while moving
  2279. #                            1 - press mouse key down - move - release
  2280. #                            2 - Click after moving - no mouse down during move
  2281. #                pHorizontalPixels is ptList    3 - MultiDrag (pressmouse - move - move - move - release)
  2282. #                            4 - move - release
  2283. #                pHorizontalPixels is ptList    5 - MultiClick (click - move - click - move - click)
  2284. #                pInset    -   inset from window rect for GetXYRandom
  2285. #                WhichCorner - Relative to which corner of the window
  2286. #                            1 - Top/Left
  2287. #                            2 - Bottom/Left
  2288. # Returns:        Nothing
  2289. # Examples:        MoveRelativeToWindow(12,25);
  2290. # Assumptions:    Assumes there is a window on the screen 
  2291. #========================================================================
  2292. # History:
  2293. # KTA    7/6/93        Performance support: Call (gBeginTimer);
  2294. # KTA    7/6/93        Move Performance Support into MoveMouse()
  2295. #########################################################################
  2296. TASK MoveRelativeToWindow(pHorizontalPixels:= 'random', pVerticalPixels:= 'random', pSpecifier:=0,pMouseDown:=0,pInset:= {30,30,30,30}, WhichCorner := 1)
  2297. begin
  2298.     returnVal := 0;                # Init error condition
  2299.     if ( pHorizontalPixels='random') begin    # user wants random mouse move
  2300.         xyRandom := GetRandomPointsRelativeToWindow(pInset, pSpecifier);
  2301.         pHorizontalPixels := xyRandom[1];
  2302.         pVerticalPixels := xyRandom[2];
  2303.         returnVal := xyRandom;
  2304.     end;
  2305.     theWind := FindWindow(pSpecifier);
  2306.     if theWind 
  2307.     begin
  2308.         lvWindRect := theWind.r;
  2309.         if(whichCorner = 1)                    # Top/Left Corner
  2310.         begin
  2311.             lvX := lvWindRect[1];            
  2312.             lvY := lvWindRect[2];
  2313.         end;
  2314.         else if(whichCorner = 2)            # Bottom/Left
  2315.         begin
  2316.             lvX := lvWindRect[1];            
  2317.             lvY := lvWindRect[4];
  2318.         end;
  2319.         else if(whichCorner = 3)            # Bottom/Right
  2320.         begin
  2321.             lvX := lvWindRect[3];            
  2322.             lvY := lvWindRect[4];
  2323.         end;
  2324.         else if(whichCorner = 4)            # Top/Right
  2325.         begin
  2326.             lvX := lvWindRect[3];            
  2327.             lvY := lvWindRect[2];
  2328.         end;
  2329.         # Handle PointList
  2330.         if (typeOF(pHorizontalPixels) = "list")            # Need to move to a list of coordinates
  2331.         begin
  2332.             MoveMouse(pHorizontalPixels,{lvX,lvY},1,pMouseDown);    # move to the calculated location
  2333.             returnVal := {lvX,lvY};
  2334.         end;
  2335.         else
  2336.         begin
  2337.             lvFinalLeft := pHorizontalPixels + lvX;            # calculate absolutely pHorizontalPixels
  2338.             lvFinalTop := pVerticalPixels + lvY;            # calculate absolutely pVerticalPixels
  2339.             MoveMouse(lvFinalLeft,lvFinalTop,1,pMouseDown);    # move to the calculated location
  2340.             returnVal := {lvFinalLeft,lvFinalTop};
  2341.         end;
  2342.     end;
  2343.     return (returnVal);
  2344. end; # MoveRelativeToWindow()
  2345.  
  2346.  
  2347. #########################################################################
  2348. #                 MoveMouse(pHorizontalPixels, pVerticalPixels, pAbsolutely, pMouseDown)
  2349. #========================================================================
  2350. # Author:        DMM
  2351. # Description:    This routine will move the mouse pHorizontalPixels,pVerticalPixels
  2352. #                relative to its current location  If pHorizontalPixels and 
  2353. #                pVerticalPixels are absent or equal to "random", a random move is generated.
  2354. # Parameters:    pAbsolutely - 1 if move pAbsolutely, 0 if relative
  2355. #                pHorizontalPixels - horizontal distance in pixels to move mouse 
  2356. #                pVerticalPixels - vertical distance in pixels to move mouse
  2357. #                                if pHorizontalPixels and pVerticalPixels are absent
  2358. #                                or := "random" then a random move is generated.
  2359. #                pAbsolutely    -    1 to move to absolute location
  2360. #                                0 to move relative to current location
  2361. #                pMouseDown - 0 - don't hold mouse key down while moving
  2362. #                            1 - press mouse key down - move - release
  2363. #                            2 - Click after moving - no mouse down during move
  2364. #                            3 - press mouse key down - move - don't release
  2365. #pHorizontalPixels is List    3 - MultiDrag
  2366. #                            4 - move - release
  2367. #pHorizontalPixels is List    5 - MultiClick
  2368. # Returns:        Nothing
  2369. #========================================================================
  2370. # History:
  2371. # KTA    9/21/93    Added gPreMoveMouseHook
  2372. #########################################################################
  2373. TASK MoveMouse(pHorizontalPixels := 'random', pVerticalPixels := 'random', pAbsolutely := 1, pMouseDown := 0)
  2374. begin
  2375.     if ( pHorizontalPixels='random') begin    # user wants random mouse move
  2376.         xyRandom := getXYRandom();
  2377.         pHorizontalPixels := xyRandom[1];
  2378.         pVerticalPixels := xyRandom[2];
  2379.     end;
  2380.     
  2381.     if ((pMouseDown = 1) or (pMouseDown = 3))
  2382.         PressMouse;
  2383.     wait(1);    #
  2384.     #### To Handle PointLists  #####
  2385.     if (typeOF(pHorizontalPixels) = "list")            # Need to move to a list of coordinates
  2386.     begin
  2387.         pointList := pHorizontalPixels;
  2388.         xOffSet := 0;
  2389.         yOffSet := 0;
  2390.         if (typeOF(y) = "list")                # If its relative to window
  2391.         begin                                # We pass in pVerticalPixels as the offset of the window
  2392.             xOffSet := pVerticalPixels[1];
  2393.             yOffSet := pVerticalPixels[2];
  2394.         end;
  2395.         if (pMouseDown = 5)                # To start the multiClick
  2396.             click;
  2397.  
  2398.         for each pairPoints in pointList
  2399.         begin
  2400.             nuX := pairPoints[1];
  2401.             nuY := pairPoints[2];
  2402.             pHorizontalPixels := nuX + xOffSet;            # If relative to window offset
  2403.             pVerticalPixels := nuY + yOffSet;            # otherwise the offset is 0
  2404.             
  2405.             if(global gPreMoveMouseHook)
  2406.                 Call(gPreMoveMouseHook);
  2407.                 
  2408.             if (pAbsolutely)
  2409.                 move a: { pHorizontalPixels, pVerticalPixels };
  2410.             else
  2411.                 move r: { pHorizontalPixels, pVerticalPixels };
  2412.                 
  2413.             if (pMouseDown = 5)        # Click for Multiclick
  2414.                 click;
  2415.         end;
  2416.         if (pMouseDown = 3)            # Finished MultiDrag
  2417.             releaseMouse;
  2418.     end;
  2419.     else
  2420.     begin
  2421.         if(global gPreMoveMouseHook)
  2422.             Call(gPreMoveMouseHook);
  2423.             
  2424.         if (pAbsolutely) begin
  2425.             move a: { pHorizontalPixels, pVerticalPixels };
  2426.             str := "Moved the mouse to absolute location ∂({pHorizontalPixels},{pVerticalPixels}∂)";
  2427.         end;
  2428.         else begin
  2429.             move r: { pHorizontalPixels, pVerticalPixels };
  2430.             str := "Moved the mouse relative ∂({pHorizontalPixels},{pVerticalPixels}∂) to previous position";
  2431.         end;
  2432.         
  2433.         wait(1);
  2434.         # release mouse if needed
  2435.         if ((pMouseDown = 1) or (pMouseDown = 4))
  2436.             ReleaseMouse;
  2437.     
  2438.         # add mouse down to log string if needed
  2439.         if ((pMouseDown = 1) or (pMouseDown = 3) or (pMouseDown = 4))
  2440.             str := "{str} with mouse button held down";
  2441.         
  2442.         # click if needed
  2443.         if (pMouseDown = 2 ) begin
  2444.             Click;
  2445.             str := "{str} and clicked";
  2446.         end;
  2447.         
  2448.         # log it
  2449.         LogStr(str);
  2450.     end;
  2451. end; # MoveMouse()
  2452.  
  2453.  
  2454. #=======================================================================
  2455. # Keyboard action related tasks:
  2456. #=======================================================================
  2457.  
  2458. #########################################################################
  2459. #                                TypeStr(pTheString)
  2460. #========================================================================
  2461. # Author:        KTA
  2462. # Description:    This routine will type the string that is passed in as 
  2463. #                the <pTheStringing>.
  2464. # Parameters:    pTheString - The string to be typed
  2465. # Returns:        Nothing
  2466. # Note: If gTypeStrOverRide is defined as a task reference, it will have to handle
  2467. #        all actions all of the functionality of TypeStr since it is being overriden.
  2468. #========================================================================
  2469. # History:
  2470. # KTA 12/2/93    Added gTypeStrOverRide
  2471. #########################################################################
  2472. TASK TypeStr(pTheString :='') 
  2473. begin
  2474.     if (global gTypeStrOverRide)
  2475.         call (gTypeStrOverRide, pTheString);
  2476.     else
  2477.     begin
  2478.         type k:{pTheString};
  2479.         LogStr("Typed '{pTheString}'");
  2480.     end;
  2481. end; # TypeStr()
  2482.  
  2483.  
  2484. #########################################################################
  2485. #                        TypeList(pStringList,pSpecialKey, pTypeFinalKey)
  2486. #========================================================================
  2487. # Author:            KTA
  2488. # Description:        This routine will type each item in the {pStringList} 
  2489. #                    and the selected special key, designated by the <pSpecialKey> 
  2490. #                    input parameter, after each item. If pTypeFinalKey = 0 the 
  2491. #                    special key will be suppressed after the last item.
  2492. # Parameters:        pStringList -    list holding strings to type
  2493. #                    pSpecialKey    -    integer representing key to type after the item has
  2494. #                            been typed. 
  2495. #                        pSpecialKey := 0 Nothing
  2496. #                        pSpecialKey := 1 (ReturnKey)
  2497. #                        pSpecialKey := 2 (TabKey)
  2498. #                        pSpecialKey := 3 (EnterKey)
  2499. #                        pSpecialKey := 4 (UpArrowKey)
  2500. #                    pTypeFinalKey - 1 to type special key after last item in <pStringList>
  2501. #                            0 to disable typing of last special key
  2502. # Return Value:        None
  2503. # Examples:            TypeList({'A','list', 'of items'},2); To type each item 
  2504. #                    and then the tabKey
  2505. # Assumptions:        None 
  2506. #========================================================================
  2507. # History:
  2508. #
  2509. ################################################################################    
  2510. TASK TypeList(pStringList,pSpecialKey := 0, pTypeFinalKey := 0) 
  2511. begin
  2512.     theWholeList := card(pStringList);
  2513.     for numtimes := 1 to theWholeList 
  2514.     begin
  2515.         if(TypeOf(pSpecialKey) = 'integer') 
  2516.         begin
  2517.             if (pSpecialKey = 1) 
  2518.                 KeyList := {ReturnKey,' and the Return Key'};
  2519.             else if (pSpecialKey = 2) 
  2520.                 KeyList := {TabKey,' and the Tab Key'};
  2521.             else if (pSpecialKey = 3)
  2522.                 KeyList := {EnterKey,' and the Enter Key'};
  2523.             else if (pSpecialKey = 4) 
  2524.                 KeyList := {UpArrowKey,' and the Up Arrow Key'};
  2525.         end;
  2526.         else 
  2527.             KeyList := {pSpecialKey,' and some Special Key???'};
  2528.         KeyName := KeyList[2];
  2529.         Item := pStringList[numtimes];
  2530.         Type k:{ Item };
  2531.         if not (numtimes = theWholeList)
  2532.         begin
  2533.             Type K:{KeyList[1]};
  2534.         end;
  2535.         else
  2536.             if(pTypeFinalKey)
  2537.                 Type K:{KeyList[1]};
  2538.             else 
  2539.                 KeyName := '';
  2540.         LogStr("Typed '{item}'{KeyName}");
  2541.         
  2542.     end;
  2543. end; # TypeList()
  2544.  
  2545.  
  2546. #########################################################################
  2547. #                SpecialKey( pTheKey, pKeyName, pNumTimes )
  2548. #========================================================================
  2549. # Author:        KTA
  2550. # Description:    This routine will type whatever SpecialKey is entered
  2551. #                However it will only log the name of the special character 
  2552. #                if the special key name is also passed in as a String in
  2553. #                the pKeyName parameter.
  2554. # Parameters:    pTheKey - the VU key-word for the special key to be typed
  2555. #                            (i.e. ReturnKey, TabKey, EnterKey, etc.)
  2556. #                pKeyName - the string name of the special key
  2557. #                pNumTimes - number of times to type the special key (default = 1)
  2558. # Returns:        Nothing
  2559. # Examples:        SpecialKey(TabKey,"TabKey");
  2560. #========================================================================
  2561. # History:
  2562. # KTA    7/6/93    Performance support: Call (gBeginTimer);
  2563. # KTA    9/21/93 Changed gBeginTimer to gPreSpecialKeyHook
  2564. # KTA    11/18/93 Log prior to performing the action
  2565. #########################################################################
  2566. TASK SpecialKey( pTheKey, pKeyName := "", pNumTimes := 1 ) 
  2567. begin
  2568.     StrExt :=  "";
  2569.     if (pNumTimes <> 1)
  2570.         StrExt :=  "- ({pNumTimes}) times";
  2571.  
  2572.     if (pKeyName ="")
  2573.         LogStr("Typing some special key {StrExt}");
  2574.     else
  2575.         LogStr ("Typing {pKeyName} {StrExt}");
  2576.  
  2577.     for x := 1 to pNumTimes
  2578.     begin
  2579.         if (global gPreSpecialKeyHook)
  2580.             Call (gPreSpecialKeyHook);
  2581.     
  2582.         type k:{ pTheKey };
  2583.     end;
  2584. end; # SpecialKey()
  2585.